1

I am using the following code to start a service periodically whether the app is foreground or not .

Intent getAlertIntent = new Intent(getApplicationContext(), GetAlertAlarmReceiver.class);
PendingIntent getAlertpendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, getAlertIntent, 0);
AlarmManager getAlertmanager = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
getAlertmanager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 10000, getAlertpendingIntent);

The code for my receiver is following

public class GetAlertAlarmReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Intent i = new Intent(context, GetAlertServiceIntent.class);
        context.startService(i);
    }
}

And and service

public class GetAlertServiceIntent extends IntentService {

    public GetAlertServiceIntent() {
        super("GetAlertServiceIntent");
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    protected void onHandleIntent(Intent intent) {
        doSomething();
    }

}

In my manifest file I declared everything as following

<receiver
    android:name=".broadcastreceiver.GetAlertAlarmReceiver"
    android:enabled="true">

    <intent-filter android:priority="999">
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

   <service
    android:name="com.surroundapps.shotorkoporibar.services.GetAlertServiceIntent" />

This code work as expected in API level below Marshmallow but in marshmallow it doesn't work .

mSapps
  • 601
  • 9
  • 24
  • Have you read here? http://stackoverflow.com/questions/32492770/how-to-make-alarm-manager-work-when-android-6-0-in-doze-mode Marshmallow added Doze mode and other things which broke the standard code used before API 23 – MatPag Jan 25 '17 at 13:11
  • yes I read that, but I couldn't find any of of repeating . The link you have given shows example for setting alarm but not repeating . I need to repeat alarm . – mSapps Jan 25 '17 at 13:20
  • So in marshmallow and above, the alarm never is set or fired? Or does it just not work at the times you want – Nick Friskel Jan 25 '17 at 19:50
  • @mSapps are you able to find the solution? – Ankur Khandelwal Apr 17 '17 at 11:13
  • @AnkurKhandelwal no, now I am using job scheduler for this purpose – mSapps Apr 19 '17 at 10:11

0 Answers0