Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the sender of Broadcast Intent

I have an application that is at the same time a broadcast sender and receiver of standard action android.intent.action.SET_WALLPAPER. I want to do some stuff only in a case when another application broadcasted this intent.

Is there any way to determine who initiated a broadcast in onReceive method of a BroadcastReceiver?

like image 446
GoranK Avatar asked Sep 20 '10 22:09

GoranK


1 Answers

If all you care about is if it was sent by your app or not, what you can do is add an extra to the Intent every time you create one. For example:

broadcastIntent.putExtra('com.android.app.EXTRA_APP_CREATED', true)

Then, when you receive the broadcast, you can check

if (intent.getExtra('com.android.app.EXTRA_APP_CREATED', false) { ... }

To see if you created the intent.

like image 112
karl Avatar answered Oct 20 '22 01:10

karl