Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Show multiple image share options of our Application like facebook?

I am creating a social media application in which user can share images, videos, audios etc. I am successful in receiving the medias that shares from third party application by adding the below code in manifest file.

<activity
        android:name=".activity.SendToActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />

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

            <data android:mimeType="*/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND_MULTIPLE" />

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

            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>

Now I want to show multiple icons of my application when a user try to share an image from their gallery like facebook(set as profile pic) to upload profile image directly. Please see the screenshot

Like facebook multiple icons are shown

Somebody please help me to show multiple icons of my application when a user try to share an image from their gallery.

like image 711
Cecil Paul Avatar asked Apr 17 '20 17:04

Cecil Paul


1 Answers

To provide custom icons and labels on a picker you need to add parameters to the intent filter on the manifest. By default it uses the parent's icon and label.

You can override those as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter
            android:icon="@drawable/ic_profile_icon" <!-- Custom icon -->
            android:label="Set as profile"> <!-- Custom label -->
            <action android:name="android.intent.action.SEND" />

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

            <data android:mimeType="*/*" />
        </intent-filter>

        <intent-filter
            android:icon="@drawable/ic_story_icon" <!-- Custom icon -->
            android:label="Share as story"> <!-- Custom label -->
            <action android:name="android.intent.action.SEND" />

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

            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
</application>

</manifest>

Please note that this is a sample app that holds no logic or value.

Hope it helps :)

like image 98
Camarero Avatar answered Oct 05 '22 04:10

Camarero