I want to turn off device screen when incoming call made.
I tried :
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?
Actually I don't have Window object to turn off in my incoming call receiver.
Here is my code :
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();
}
}
}
Can anybody help plz.