How to make my Android app appear in the share list of another specific app

Add this code in the activity you want opened first when sharing a content from outside the app, call this method in onCreate()

private void onSharedIntent() {
    Intent receiverdIntent = getIntent();
    String receivedAction = receiverdIntent.getAction();
    String receivedType = receiverdIntent.getType();

    if (receivedAction.equals(Intent.ACTION_SEND)) {

        // check mime type 
        if (receivedType.startsWith("text/")) {

            String receivedText = receiverdIntent
                    .getStringExtra(Intent.EXTRA_TEXT);
            if (receivedText != null) {
                //do your stuff
            }
        }

        else if (receivedType.startsWith("image/")) {

            Uri receiveUri = (Uri) receiverdIntent
                    .getParcelableExtra(Intent.EXTRA_STREAM);

            if (receiveUri != null) {
                //do your stuff
                fileUri = receiveUri;// save to your own Uri object

                Log.e(TAG,receiveUri.toString());
            }
        }

    } else if (receivedAction.equals(Intent.ACTION_MAIN)) {

        Log.e(TAG, "onSharedIntent: nothing shared" );
    }
}

Add this in Manifest,

 <activity
            android:name="your-package-name.YourActivity">
            <intent-filter>
                <action android:name="android.intent.action.SEND" /> 

                <category android:name="android.intent.category.DEFAULT" />      
                <data android:mimeType="image/*" />
                <data android:mimeType="text/*" />
            </intent-filter>
        </activity>

Leave a Comment