她就是我要完成的:
当用户试图从共享的任何应用程序的一些文字(像共享鸣叫或链接),我的应用程序将出现在共享列表中。 如果他选择我的应用程序,一些简单的code将运行(如呈现出吐司),那么仅此而已。无接口或UI是必要的。下面是我做的:
AndroidManifest.xml中
<接收器
机器人:MyBroadcastReceiverNAME =>
<意图过滤器
机器人:标签=选择我的应用程序>
<作用机器人:名称=android.intent.action.SEND/>
<类机器人:名称=android.intent.category.DEFAULT/>
<数据机器人:MIMETYPE =text / plain的/>
&所述; /意图滤光器>
< /接收器>
MyBroadcastReceiver.java
公共无效的onReceive(背景为arg0,意图ARG1){
// TODO自动生成方法存根
//一些简单的code
Toast.makeText(arg0中,我的收款人是酷,Toast.LENGTH_LONG).show();
}
这没有工作,我的应用程序不会在共享列表中显示。
为什么我用 BroadcatReceivers
工作,不与活动
?因为我不吨要任何UI,我认为这就是为什么我们有接收器(纠正我的PLZ)
我这样做对吗?
解决方案这没有工作,我的应用程序不会在共享列表中显示。
ACTION_SEND
用于与活动。您正在尝试使用的BroadcastReceiver
。由于的BroadcastReceiver
不是一个活动,这是不行的。
我这样做对吗?
没有。
如果他选择我的应用程序,一些简单的code将运行(如呈现出吐司),那么仅此而已。无接口或UI是必要的。
您还需要一个活动。但是,如果你给的活动 Theme.NoDisplay
,你不叫的setContentView()
,将不会有用户界面的活性。通常情况下,你只需要调用完成()
从的onCreate()
做什么是你想做的事(在此之后,情况下,显示吐司
)。
例如,这个示例应用程序展示活动( FauxSender
)设置做$ P $你想pcisely什么:以吐司回应
。它有发出 ACTION_SEND
ACTION_SEND
这样你就可以看到结果。
Her is what I'm trying to accomplish:
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. 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.Here is how I did it:
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();
}
This didn't work, my app doesn't show in the sharing list.
Why I work with BroadcatReceivers
and not with Activities
? Because I don't want any UI and I think that is why we have receivers (correct my plz)
Am I doing it right?
解决方案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.
上一篇:Android的CircularPageIndicator在统筹布局不显示布局、Android、CircularPageIndicator
下一篇:窗口管理器,$ BadTokenException Android中管理器、窗口、Android、BadTokenException