java - I want message or notification show when start or boot android mobile. -
i want message or notification show when start or boot android mobile. notification show when destroyed application not showing message or notification. please me.
public class beaconservice extends service { handler mhandler = new handler(); @override public ibinder onbind(intent arg0) { return null; } @override public int onstartcommand(intent intent, int flags, int startid) { new thread(new runnable() { @override public void run() { while (true) { try { thread.sleep(10000); mhandler.post(new runnable() { @override public void run() { shownotification(); } }); }catch (exception e){ } } } }).start(); return start_sticky; } private void shownotification() { notificationcompat.builder mbuilder = (notificationcompat.builder) new notificationcompat.builder(this) .setsmallicon(r.drawable.ic_loc) .setcontenttitle("welcome ford show room") .setcontenttext("hello puneet, welcome ford! you'll shortly attended karthik! ") .setpriority(2) .setonlyalertonce(true); intent resultintent = new intent(this, slidemenuactivity.class); taskstackbuilder stackbuilder = taskstackbuilder.create(this); stackbuilder.addparentstack(slidemenuactivity.class); stackbuilder.addnextintent(resultintent); notificationmanager mnotificationmanager = (notificationmanager) getsystemservice(context.notification_service); mnotificationmanager.notify(2001, mbuilder.build()); } }
beaconreceiverservice.java
public class beaconreceiverservice extends broadcastreceiver { @override public void onreceive(context context, intent intent) { log.d("debug", "creating intent"); intent service = new intent(context, beaconservice.class); context.startservice(service); } }
services in menifest.xml
<service android:name=".beaconservice" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> </intent-filter> </service> <receiver android:name=".beaconreceiverservice"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> </intent-filter> </receiver>
this below thing worked well
androidmanifest.xml
<uses-permission android:name="android.permission.receive_boot_completed" /> <application > <receiver android:name=".bootcompletedreceiver" > <intent-filter> <action android:name="android.intent.action.boot_completed" /> <action android:name="android.intent.action.quickboot_poweron" /> </intent-filter> </receiver> <service android:name="notifyingdailyservice" > </service>
bootcompletedreceiver class
public class bootcompletedreceiver extends broadcastreceiver { @override public void onreceive(context context, intent arg1) { // todo auto-generated method stub context.startservice(new intent(context, notifyingdailyservice.class)); } }
service class
public class notifyingdailyservice extends service { @override public ibinder onbind(intent arg0) { // todo auto-generated method stub return null; } @override public int onstartcommand(intent pintent, int flags, int startid) { // todo auto-generated method stub toast.maketext(this, "notification", toast.length_long).show(); return super.onstartcommand(pintent, flags, startid); } }
Comments
Post a Comment