android - broadcast receiver works but after 1 or 2 hours it does not work -
here manifest
<receiver android:name=".mycallreceiver" > <intent-filter> <action android:name="android.intent.action.phone_state" /> </intent-filter> </receiver>
and
public class mycallreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { if (intent.getstringextra(telephonymanager.extra_state).equals(telephonymanager.extra_state_ringing)) { code } if (intent.getstringextra(telephonymanager.extra_state).equals(telephonymanager.extra_state_idle) || intent.getstringextra(telephonymanager.extra_state).equals(telephonymanager.extra_state_offhook)){ code } } }
it works after sometime press button , phone idle doesn't work more
(i added "android.os.process.killprocess(android.os.process.mypid());" @ end of code , better , work maybe 2 3 hour after last execute)
you can use alarm manger broadcast receiver after interval of time this.
public static void scheduletestalarmreceiver(context context) { intent receiverintent = new intent(context, testalarmreceiver.class); pendingintent sender = pendingintent.getbroadcast(context, 123456789, receiverintent, 0); alarmmanager alarmmanager = (alarmmanager)context.getsystemservice(context.alarm_service); alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup, systemclock.elapsedrealtime()+startdelay, somedelay, sender); }
Comments
Post a Comment