Search code examples
androidandroid-intentandroid-manifestintentfilter

Share intent filter


I am building an app that allows people to share apps with each other. I am already able to do this from inside this app (I show the installed apps and the user can select the ones he wants to send), but now I would like to share apks that are not installed, so the apk is just on the downloads folder or something similar.

Imagine that you have an apk in the Download folder for example, I would like to be able to by pressing Share, to go to inside my app and send that apk. It is just like any other share (images,etc).

I was able to make my app to pop up on the list of apps that can share that type of file (in this case .apk), like on this picture (bellow) by adding this to my manifest inside one of the activities tags:

<intent-filter>
    <action android:name="android.intent.action.SEND" />

    <category android:name="android.intent.category.DEFAULT" />

    <data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>

Share image list

Now the problems are :

1 - How do I know the filepath of the file that the person pressed share?

2 - How do I pass that filepath to my app if the intent is being received on the manifest ?

PS: Notice that the goal is to share an apk from any folder on the device by pressing share (long press and then share - depends on the device).

Thanks in advance for all of the help.


Solution

  • Sorry for answering to my own question, but maybe this will help someone in the future. I was debugging and looking inside the extras if there was anything, and nothing showed up. The solution was doing (ArrayList<Uri>) getIntent().getExtras().get("android.intent.extra.STREAM"); and this would "refresh" the Extras from the intent. I don't know why these extras don't show up initially and only after i get the extra stream, but it is working. I used an arraylist of uri's because in this case i was trying with send_multiple. If you are only using SEND then you don't need the ArrayList part.