-1

How to achieve the LocalBroadcastManager functionality using the normal broadcasts programmatically without keeping any thing in the manifest. My goal is to limit my broadcast scope to my own application.

Pavandroid
  • 1,586
  • 2
  • 15
  • 30
  • *My goal is to limit my broadcast scope to my own application* - Exactly what `LocalBroadcastManager` does. *...without keeping any thing in the manifest.* - Exactly what `LocalBroadcastManager` does. – user May 08 '13 at 07:16

1 Answers1

1

To broadcast an Intent within your application's context then LocalBroadcastManager is the safest way to do it. However, if you want to achieve the similar functionality via ordinary broadcast procedures then you may explicitly define a package which should listen your broadcast. For example:

Intent intent = new Intent("com.abc.my_action");
intent.setPackage("com.package.other");  //Set an explicit application package 
sendBroadcast(intent);

This restriction for broadcasts is available in ICS and onwards. For more info read this.

P.S. I would still recommend you to stick with LocalBroadcastManager as it broadcasts intents within your application's context and is considered to be the safest.

Community
  • 1
  • 1
waqaslam
  • 67,549
  • 16
  • 165
  • 178
  • Is it necessary to include android-support-v4.jar to use LocalBroadcastManager, even though I am targeting ICS (android-14) onwards? – IgorGanapolsky Feb 27 '14 at 16:52
  • 1
    Yes, `LocalBroadcastManager` is available only through **android-support-v4** package which is the most secure way for communicating inside your application's context. But if you don't want to use it in your ICS build project then as an alternate you may rely on less secure ways like `intent.setPackage` and/or `intent.setComponent`. – waqaslam Feb 27 '14 at 21:28
  • I'm guessing Google is working on an alternative implementation of LocalBroadcastManager going forward, if they didn't include this api in their latest master branch on Git for KitKat. I doubt their intention is to force all developers to start being backwards compatible with android-support-v4 again... – IgorGanapolsky Feb 28 '14 at 15:03