Search code examples
androidandroid-sharing

Android share link and images through my application


I want to add the ability to share an image or link through my application. For this I added in the manifest those filters

<activity android:name="MyActivity" 
          android:launchMode="singleTask"
          android:screenOrientation="portrait"
>
    <intent-filter>
       <action android:name="android.intent.action.SEND" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="image/*" />
    </intent-filter>
    <intent-filter>
       <action android:name="android.intent.action.SEND" />
       <category android:name="android.intent.category.DEFAULT" />
       <data android:mimeType="text/plain" />
   </intent-filter>
</activity>

this activity is basically the main one, I mean when the user will launch the application, this activity will be open.

now, when I swipe the application and share a youtube link through my application I get the data and it works fine, the problem is when I launch the application then press the home button (in this case the application is on background), and then try to share a youtube link I don't get the data from the intent.

any suggestions?


Solution

  • Looks like you should add the handling not only in onCreate but as well in onNewIntent method. singleTask forces android to deliver the intent via onNewIntent if the activity is already created.