通过&QUOT启动服务; android.intent.action.SEND"意图 [英] Starting service via "android.intent.action.SEND" intent

查看:173
本文介绍了通过&QUOT启动服务; android.intent.action.SEND"意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个具有以下意向过滤器的活动类:

I currently have an Activity class that has the following intent-filter:

        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:mimeType="image/*"></data>
        </intent-filter>

这会使我的应用程序从库共享,通过菜单来显示。这是所有好的。

This causes my application to show up in the Share-Via menu from the Gallery. Which is all good.

现在,我实际上并不需要希望这是一个活动,因为它不需要用户交互。相反,我想让它变成是由库共享,通过菜单以同样的方式启动的服务。所以,我提出了意向性过滤器,如服务标签中:

Now, I don't actually need want this to be an Activity, as it requires no user interaction. Instead, I want to make it into a service that is started in the same way by the Share-Via menu in the Gallery. So I have moved the intent-filter inside the "service" tag like:

    <service ...>
        <intent-filter>
            <action android:name="android.intent.action.SEND"/>
            <category android:name="android.intent.category.LAUNCHER" />
            <data android:mimeType="image/*"></data>
        </intent-filter>
      </service>

不过,现在我再也看不到应用程序中共享,通过菜单!这是为什么?我需要什么改变来列出共享,通过菜单的服务?

However, now I no longer see the app in the Share-Via menu! Why is that? What do I need to change to list the service in the Share-Via menu?

推荐答案

这是因为Android把 startActivity()方法时分享菜单项用户点击。您可以创建一个透明的活动,并从它启动服务。

That's because Android calls startActivity() method when user clicks on Share menu item. You can create a transparent activity and start the service from it.

这篇关于通过&QUOT启动服务; android.intent.action.SEND&QUOT;意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆