I need to implement a sort of call functionality with the help of Firebase notification but the problem is the screen that is visible on the notification received is not showing if the screen is locked can anyone give any tips about that? Regards,
Asked
Active
Viewed 51 times
1 Answers
0
Just done that by using Power Manager
AndroidManifest.xml
<activity
android:name=".IncomingCall"
android:exported="false"
android:launchMode="singleInstance"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait" />
Activity from where to shift
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "myalarmapp:alarm.");
wl.acquire(5000);
Intent startAlarmActivity = new Intent(getApplicationContext(), IncomingCall.class);
startAlarmActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startAlarmActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startAlarmActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(startAlarmActivity);
wl.release();
Destination Activity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
keyguardManager.requestDismissKeyguard(this, null);
} else {
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}

Aaraf Rao
- 19
- 1
- 4