Android Studio:Need help in IntentFilter -
i'm doing small program in android studio , need in code:
intent myintent = new intent(this , notifyservice.class); pendingintent pendingintent = pendingintent.getservice(this, 0, myintent, 0); alarmmanager alarmmanager = (alarmmanager)getsystemservice(alarm_service); calendar calendar = calendar.getinstance(); alarmmanager.setinexactrepeating(alarmmanager.elapsed_realtime_wakeup, systemclock.elapsedrealtime() + alarmmanager.interval_fifteen_minutes, alarmmanager.interval_day, pendingintent); broadreceiver receiver = new broadreceiver(); intentfilter filter = new intentfilter("i need here!"); registerreceiver(receiver, filter); return super.onstartcommand(intent, flags, startid);
so, in line i need here, when wrote intent.action_airplane_mode_changed
runs should be, need code above function of action_airplane_mode_changed
. basically, every fifteen minutes background program (this code there) should open notification.
if need more code say.
first of all. alrammanager
's pendingintent
contains intent
fired when alarm fired. so, should change:
intent myintent = new intent(this , notifyservice.class);
to this
intent myintent = new intent(this , broadreceiver.class);
here can find more detailed examples google's alarm guide
if want use implicit intent, can try this:
intent myintent = new intent(); myintent.setaction("your_action"); pendingintent pendingintent = pendingintent.getservice(this, 0, myintent, 0); // setup alarmmanager broadreceiver receiver = new broadreceiver(); intentfilter filter = new intentfilter("your_action"); registerreceiver(receiver, filter);
Comments
Post a Comment