她就是我要完成的工作:
>当用户尝试共享任何应用程序中的某些文本(例如共享推文或链接)时,我的应用程序将出现在共享列表中.
>如果他选择了我的应用程序,那么将运行一些简单的代码(例如显示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,因此您可以查看结果.
总结以上是内存溢出为你收集整理的与他们的意图过滤器的BroadcastReceiver?全部内容,希望文章能够帮你解决与他们的意图过滤器的BroadcastReceiver?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)