For waking the device you need to use this,
https://stackoverflow.com/a/10222999/7006744
also, you need to define permission
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
before displaying an overlay, you need to ask permission to overlay by using the below code.
startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName())).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
At last, you need to set BroadcastReceiver to PendingIntent of AlarmManager.
By using the below code.
Intent alarmIntent = new Intent(context, BroadcastReceiver.class)
.setAction(ALARM_ACTION);
PendingIntent pending = PendingIntent.getBroadcast(context,
ALARM_REQUEST_CODE, alarmIntent, PendingIntent.FLAG_MUTABLE);
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
you need to define in the activity in manifest code,
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
In the BroadcastReceiver, you can call intent for overlay view
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays(context)) {
context.startActivity(new Intent().setClassName(context.getPackageName(), context.getPackageName() + ".OverlayActivity")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
} else {
context.startActivity(new Intent().setClassName(context.getPackageName(), context.getPackageName() + ".OverlayActivity")
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}