When app is running and device is locked I'm able to start the activity. But when app is in background and device is locked not able to start the activity even though I'm getting the control in BroadcastReceiver class. This is my intent call.
context.startActivity(new Intent(context, ReceiveCallActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setAction(Intent.ACTION_ANSWER)
.putExtra("title", intent.getStringExtra("title"))
.putExtra("action", intent.getStringExtra("action")));
Manifest of Activity
<activity
android:name=".ReceiveCallActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:excludeFromRecents="true"
android:launchMode="singleTop"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustPan|stateHidden" />
ReceiveCallActivity.class
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
setContentView(R.layout.receive_call_activity);
...
...
}
setShowWhenLocked(true) && setTurnScreenOn(true)
helps to open app even if device is locked but app has to be in foreground for that.
PS: I'm getting the control in BroadcastReceiver in all scenarios.
TIA