android - Why this code does not make a notification in BroadcastReceiver -
i want make notification broadcastreceiver. i'm using code in activity , works fine can't make notification broadcastreceiver . me solve problem :
random rd;rd= new random (); notificationmanager notificationmanager = (notificationmanager) ctx.getsystemservice(context.notification_service); intent notificationintent = new intent(intent.action_view); notificationintent.setdata(uri.parse(link)); pendingintent pending=null; pending = pendingintent.getactivity(ctx, 0, notificationintent, pending.flag_update_current); notification mynotification = new notificationcompat.builder(ctx) .setsmallicon(r.drawable.ic_launcher).setautocancel(false).setlargeicon(remote_picture) .setcontenttitle(onvan).setstyle(new notificationcompat.bigtextstyle().bigtext(msg)) .setcontenttext(msg).setcontentintent(pending).build(); notificationmanager.notify(rd.nextint(75), mynotification);
the problem , code not make notification , no notification showing in tray .as , run code in activity , works find in broadcastreceiver not make notifications
to execute code inside broadcastreceiver have call sendbroadcast() method or set action in manifest file like
<receiver android:name="your package name.receivername"> <intent-filter> <action android:name="android.intent.action.boot_completed" /> //set action here </intent-filter> </receiver>
Comments
Post a Comment