标签:android android-intent broadcastreceiver
她就是我要完成的工作:
>当用户尝试共享任何应用程序中的某些文本(例如共享推文或链接)时,我的应用程序将出现在共享列表中.
>如果他选择了我的应用程序,那么将运行一些简单的代码(例如显示Toast),仅此而已.不需要界面或UI.
这是我的做法:
AndroidManifest.xml中
<receiver
android:name=".MyBroadcastReceiver" >
<intent-filter
android:label="select my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</receiver>
MyBroadcastReceiver.java
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
//Some simple code
Toast.makeText(arg0, "My Receiver is cool", Toast.LENGTH_LONG).show();
}
这不起作用,我的应用程序未显示在共享列表中.
为什么我与BroadcatReceivers一起工作而不与Activity一起工作?因为我不想要任何用户界面,所以我认为这就是为什么我们有接收者(更正我的plz)
我做对了吗?
解决方法:
This didn’t work, my app doesn’t show in the sharing list.
ACTION_SEND用于活动.您正在尝试使用BroadcastReceiver.由于BroadcastReceiver不是活动,因此无法使用.
Am I doing it right?
没有.
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.
您仍然需要一项活动.但是,如果为活动分配Theme.NoDisplay,并且不调用setContentView(),则该活动将没有UI.通常,您只需要在完成您想做的事情后从onCreate()调用finish()(在这种情况下,显示Toast)即可.
例如,this sample application显示一个活动(FauxSender),该活动设置为精确执行您想要的操作:用Toast响应ACTION_SEND.它有另一个活动,发出ACTION_SEND,因此您可以查看结果.
标签:android,android-intent,broadcastreceiver 来源: https://codeday.me/bug/20191009/1877650.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。