BroadcastReceiver with intent-filter for them?

前端 未结 1 1100
生来不讨喜
生来不讨喜 2021-01-16 12:46

Her is what I\'m trying to accomplish:

  1. When user tries to share some text from any app (Like sharing a tweet or a link), my app will appear in the sharing list
相关标签:
1条回答
  • 2021-01-16 13:31

    This didn't work, my app doesn't show in the sharing list.

    ACTION_SEND is used with activities. You are attempting to use a BroadcastReceiver. Since a BroadcastReceiver is not an activity, this will not work.

    Am I doing it right?

    No.

    If he select my app, some simple code will be run (like showing a Toast) then that's it. No interface or UI is needed.

    You still need an activity. However, if you give the activity Theme.NoDisplay, and you do not call setContentView(), there will be no UI for the activity. Usually, you just call finish() from onCreate() after doing whatever it is you wanted to do (in this case, display a Toast).

    For example, this sample application shows an activity (FauxSender) set up to do precisely what you want: respond to ACTION_SEND with a Toast. It has another activity that issues an ACTION_SEND so you can see the results.

    0 讨论(0)
提交回复
热议问题