android - custom broadcast receiver permission -
i have activity inside method send broadcast custom receiver located in activity's fragment...i set permission second parameter of sendbroadcast receiver can receive specific broadcasts...
activity's sendbroadcast():
@override public void update(observable observable, object connectionstatus) { log.e(debugtag, connectionstatus+""); intent = new intent("networkstateupdated"); intent.putextra("connectivitystatus", (int) connectionstatus); sendbroadcast(intent, "mypermission"); } initialization of custom receiver inside fragment's onactivitycreated
broadcastreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { connectionstatus = intent.getextras().getint("connectivitystatus"); } }; @override public void onresume() { super.onresume(); getactivity().registerreceiver(broadcastreceiver, new intentfilter("networkstateupdated"), "mypermission", null); } @override public void onpause() { super.onpause(); getactivity().unregisterreceiver(broadcastreceiver); } setting "mypermission" second parameter of sendbroadcast apparently not working..
use system broadcasts (e.g., sendbroadcast() called on context) when need send messages between processes.
within process, using system broadcasts adds ipc overhead , security concerns. instead, use sort of in-process event bus. personally, use greenrobot's eventbus. localbroadcastmanager part of android support libraries. others prefer square's otto or other event bus implementations. these less expensive in terms of overhead, , private app, there no new security concerns.
Comments
Post a Comment