Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting service via "android.intent.action.SEND" intent

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?

like image 797
user914453 Avatar asked Nov 26 '25 10:11

user914453


1 Answers

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.

like image 121
Michael Avatar answered Nov 29 '25 00:11

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!