I use the ALARM_SERVICE
with the following BroadcastReceiver
, in oreder to start my OnReceiveActivity
:
public class AlarmReciever extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
try {
Intent i = new Intent();
i.setClassName("com.test", "co.test.OnReceiveActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
i.addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON +
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);
context.startActivity(i);
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I try it without any of the specified WindowManager.LayoutParams
flags (while the device is awake and unlocked) - everything works as expected, meaning onReceive()
is called, and starts OnReceiveActivity
successfully. however, when the flags are present, it doesn't work, neither when the device is asleep and looked, nor when its awake and unlocked.
The following permission were specified at the manifest file:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />