How to determine the sender of Broadcast Intent

后端 未结 2 1107
甜味超标
甜味超标 2020-12-20 20:40

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

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-20 21:23

    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.

提交回复
热议问题