【发布时间】:2014-03-28 17:49:33
【问题描述】:
我想在来电时关闭设备屏幕。
我试过了:
How to turn screen off or send device to sleep
Android: How to turn screen on and off programmatically?
Android - Turn off display without triggering sleep/lock screen - Turn on with Touchscreen
How to distinguish the screen on/off status while incoming call?
实际上,我的来电接收器中没有要关闭的 Window 对象。
这是我的代码:
public class MyCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_RINGING)) {
// This code will execute when the phone has an incoming call
// get the phone number
String incomingNumber = intent
.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call from:" + incomingNumber,
Toast.LENGTH_LONG).show();
// I tried code here
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)
|| intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_OFFHOOK)) {
// This code will execute when the call is disconnected
Toast.makeText(context, "Detected call hangup event",
Toast.LENGTH_LONG).show();
}
}
}
有人可以帮忙吗?
【问题讨论】:
标签: android