android - Repeating alarm is not working in marshmallow -
i using following code start service periodically whether app 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 receiver following
public class getalertalarmreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { intent = new intent(context, getalertserviceintent.class); context.startservice(i); } }
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 manifest file declared 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 expected in api level below marshmallow
in marshmallow doesn't work .
Comments
Post a Comment