share list of Images from gallery and any type of files from outside our application:

159 Views Asked by At

I'm trying to share a list of images from the gallery into my app to use it recycler view or any thing else

<activity
    android:icon="@mipmap/ic_launcher"
    android:name=".MainActivity"
    >
    <intent-filter>


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

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

    <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.SEND"/>
        <data android:mimeType="*/*"/>


    </intent-filter>
</activity>
1

There are 1 best solutions below

0
On

that works:-

1-specify these lines on the manifest

  <activity
        android:icon="@mipmap/ic_launcher"
        android:name=".MainActivity"
        >
        <intent-filter>


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

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

        <category android:name="android.intent.category.DEFAULT" />
            <action android:name="android.intent.action.SEND_MULTIPLE"/>
            <data android:mimeType="*/*"/>
        <data android:mimeType="image/jpeg" />
        <data android:mimeType="image/png" />
        <data android:mimeType="image/jpg" />

        </intent-filter>
    </activity>

2-Second get the action that opened your intent and check if its the one we registered for the activity and then the data is received as ArrayList of Uri

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent intent = getIntent();
    if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
        Bundle extras = intent.getExtras();
        if (extras.containsKey(Intent.EXTRA_STREAM)) {
            ArrayList<Uri> urisArrayList = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
            urisArrayList.forEach(i-> Log.d(TAG, "onCreate: "+i.toString()));
        }
    }}