android - How to send an ordered broadcast in a PendingIntent? -
i want send ordered broadcast in pendingintent. i've found pendingintent.getbroadcast(this, 0, intent, 0)
, think can send regular broadcast. so, can do?
i got http://justanapplication.wordpress.com/tag/pendingintent-getbroadcast:
if onfinished argument not null ordered broadcast performed.
so might want try calling pendingintent.send onfinished argument set.
however, ran problem had send orderedbroadcast notification. got working creating broadcastreceiver forwards intent orderedbroadcast. don't know whether solution.
so started out creating intent holds name of action forward extra:
// name of action of our orderedbroadcast forwarder intent intent = new intent("com.youapp.forward_as_ordered_broadcast"); // name of action send orderedbroadcast intent.putextra(orderedbroadcastforwarder.action_name, "com.youapp.some_action"); intent.putextra("some_extra", "123"); // etc.
in case passed pendingintent notification:
pendingintent pendingintent = pendingintent.getbroadcast(context, 0, intent, 0); notification notification = new notificationcompat.builder(context) .setcontenttitle("notification title") .setcontenttext("notification content") .setsmallicon(r.drawable.notification_icon) .setcontentintent(pendingintent) .build(); notificationmanager notificationmanager = (notificationmanager)context .getsystemservice(context.notification_service); notificationmanager.notify((int)system.nanotime(), notification);
then defined following receivers in manifest:
<receiver android:name="com.youapp.orderedbroadcastforwarder" android:exported="false"> <intent-filter> <action android:name="com.youapp.forward_as_ordered_broadcast" /> </intent-filter> </receiver> <receiver android:name="com.youapp.pushnotificationclickreceiver" android:exported="false"> <intent-filter android:priority="1"> <action android:name="com.youapp.some_action" /> </intent-filter> </receiver>
then orderedbroadcastforwarder looks follows:
public class orderedbroadcastforwarder extends broadcastreceiver { public static final string action_name = "action"; @override public void onreceive(context context, intent intent) { intent forwardintent = new intent(intent.getstringextra(action_name)); forwardintent.putextras(intent); forwardintent.removeextra(action_name); context.sendorderedbroadcast(forwardintent, null); } }
Comments
Post a Comment