Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit broadcast to its own Android app

I wondering if it is possible to create a private broadcast. I actually register broadcastreceiver in my activity and use

sendOrderedBroadcast(broadcast);

method to send the broadcast. But, for now, the intent (broadcast) used for this method is defined like this :

Intent broadcast = new Intent("com.mypackage.broadcast");

So every external application which declare this package name can listen what I am sending, and I don't want to.

So how to make this impossible, that no one can listen my broadcast ?

like image 474
Bibu Avatar asked Aug 08 '13 06:08

Bibu


People also ask

How do I restrict broadcasting the current app?

setAction(packageName + "<MY_ACTION>"); context. sendBroadcast(intent); Since the application package would remain unique for all apps on android, this would safely limit the Broadcast to your own app and you can register BroadcastReceivers in AndroidManifest. xml.

What is the limit of broadcast receiver in Android?

As a general rule, broadcast receivers are allowed to run for up to 10 seconds before they system will consider them non-responsive and ANR the app.

How do you manage broadcast receivers?

An application listens for specific broadcast intents by registering a broadcast receiver in AndroidManifest. xml file. Consider we are going to register MyReceiver for system generated event ACTION_BOOT_COMPLETED which is fired by the system once the Android system has completed the boot process.


1 Answers

I think you are looking for LocalBroadcast Manager. The docs say:

It is a helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent). One of them is that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data.`

See how to use LocalBroadcastManager? for more. Hope it helps you.

like image 161
Shobhit Puri Avatar answered Sep 23 '22 12:09

Shobhit Puri