指定服务的SEND(共享)意图过滤器 [英] Specifying a SEND (sharing) intent filter for a Service
问题描述
我正在尝试在我的服务
android.intent.action.SEND 动作过滤和处理意图> s。我在 AndroidManifest.xml
中写了以下内容:
I am trying to filter and handle intents with android.intent.action.SEND
actions in one of my Service
s. I wrote the following in my AndroidManifest.xml
:
<service
android:name=".app.ScreamerService"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</service>
现在,问题是我没有在共享通过列表中看到我的应用程序例如,当尝试从浏览器共享网页或从联系人列表中共享联系人时的选项。但是,如果将意图过滤器移到主要的< activity>
标记(而不是< service>
),我的应用程序名称和图标做出现在共享方式选项列表中。
Now, the problem is that I don't see my application in the list of "share via" options when, for instance, trying to share a web page from the browser or a contact from the list of contacts. If, however, I move the intent filters to the main <activity>
tag (instead of the <service>
), my application name and icon do appear on the list of "share via" options.
我在这里做错了什么? SEND
操作不能定向到服务吗?
What am I doing wrong here? Can't a SEND
action be directed to a Service?
推荐答案
我正在尝试使用我的一项服务中的android.intent.action.SEND操作过滤和处理意图。
I am trying to filter and handle intents with android.intent.action.SEND actions in one of my services.
ACTION_SEND
是一项活动操作,因此不能被服务或广播接收者接收。
ACTION_SEND
is an activity action and therefore cannot be picked up by services or broadcast receivers.
现在,问题是当
Now, the problem is that I don't see my application in the list of "share via" options when, for instance,
$ b时,我的应用程序不在共享方式选项列表中$ b
那是因为它不是活动。
That is because it is not an activity.
不能将SEND操作定向到服务吗?
Can't a SEND action be directed to a Service?
选择器中显示的内容(例如,对于 ACTION_SEND
) 。不过,欢迎您与您的活动进行服务沟通。
Things that appear in a chooser (e.g.,. for ACTION_SEND
) must be activities. Your activity is welcome to communicate with a service, though.
这篇关于指定服务的SEND(共享)意图过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!