This is my Activity
code,
Long time = new GregorianCalendar().getTimeInMillis()+20000;//Setting alarm after 20 sec
Intent intentAlarm = new Intent("alarm");
intentAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentAlarm.putExtra("req_code",10);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,10, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
These are all the permissions that I have in my app,
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="com.myapp.pack.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
This is my BroadcastReceiver
code,
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPreferences =
context.getSharedPreferences( "mydata", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("elligible",true);
editor.apply();
}
I have registered my BroadcastReceiver
in the manifest,
<receiver android:name="com.myapp.pack.AlarmReciever" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="alarm" />
</intent-filter>
</receiver>
The above code successfully executes the BroadcastReceiver
on pre-MarshMallow devices in the background ,but on a MarshMallow device ,the BroadcastReceiver
does not get executed. Does anyone know what could be happening here? Thanks.
setExactAndAllowWhileIdle()
will I have to change minimum sdk version of my app to 23? – Expiate