Starting service via “android.intent.action.SEND” intent

我们两清 提交于 2020-01-01 14:35:01

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/7260790/starting-service-via-android-intent-action-send-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!