1

i know my question is similar of this but i didnt find any ans there, so i thought i should have ask here.

app is running fine if i share image from gallery but dont work if i share image from file manager. let me try to explain in details.

EDIT

i have build an app. basically i want to share some images from gallery or file manager to my app. my app only runs when i choose images from gallery and click on share button then click on my application name. that way i can get images selected by me from gallery. however, i do same thing from file-manager app ( i.e solid explorer , ES file explorer ) i couldn't get any images in my app.

may be i would get any solution here.

here is my Manifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity" >
        <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_MULTIPLE" />

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

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

and here is MainActivity.xml

@Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent mIntent = getIntent();
    String action = mIntent.getAction();
    String type = mIntent.getType();

    if(action.equals(Intent.ACTION_SEND) && type != null){
        if(type.startsWith("image/")){
            Uri mUri = mIntent.getParcelableExtra(Intent.EXTRA_STREAM);
            ImageModel imageModel = new ImageModel();
            imageModel.setName("Image 1");
            imageModel.setUri(mUri);

            data.add(imageModel);
        }
    }
    else if(action.equals(Intent.ACTION_SEND_MULTIPLE) && type != null){
        ArrayList<Uri> mUris = mIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for(int i=0;i<mUris.size();i++){
            ImageModel m = new ImageModel();
            m.setName("Image "+ i);
            m.setUri(mUris.get((i)));
            data.add(m);
        }
    }
    else
    {
        Toast.makeText(this,"from outside",Toast.LENGTH_SHORT).show();
    }
}
Community
  • 1
  • 1
Vishal Patel
  • 554
  • 6
  • 15
  • "but dont work if i share image from file manager" -- please edit your question and explain, **in detail**, what "dont work" means. – CommonsWare Mar 21 '16 at 17:40
  • edited. hope it helps you to solve problem. tell me if u need more explanation – Vishal Patel Mar 21 '16 at 17:48
  • "i couldn't get any images in my app" -- what does this mean? Usually, problems in this area come from [misusing `Uri` values](https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html), but that is just a guess. – CommonsWare Mar 21 '16 at 17:52
  • The problem is I have put if else conditions to check whether my app invoked from gallery or out side from gallery ( means from launcher) and i think that else part is also means for file manager but Its not working when I share images from file manager. I think there is no uri problem. – Vishal Patel Mar 21 '16 at 17:56
  • I can add Uri`s from galery and from file manager ("My Files") using the code in your question. I use Samsung s6 version 5.1.1 and it works. On my side Action and Type are the same when sharing images from galery or from "my files". Maybe try to debug and check what is the intenet recivied from file manager on your device and what it's action and type. – Udi Reshef Sep 25 '16 at 14:28
  • 1
    So how did you solve this? Can you please share solution? – Atul Jun 21 '17 at 15:18
  • I'm sorry but I do not remember it now. :) – Vishal Patel May 20 '19 at 16:10
  • @atul did you get solution, I also have the same issue – Venkatesh Aug 29 '19 at 10:22
  • 1
    @Venkatesh Not exactly sure but please check [this](https://stackoverflow.com/q/46578918/1911652) – Atul Sep 03 '19 at 10:20

2 Answers2

0

To share single from Gallery or File Manager use this

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

            </intent-filter>
        </activity>
Quick learner
  • 10,632
  • 4
  • 45
  • 55
0

@VishalPatel

You don not need to change anything, every thing seems right. just put your code in the onNewIntent() Method. You need to override method in your activity.

Here is the demonstration :

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    Intent mIntent = intent;
    String action = mIntent.getAction();
    String type = mIntent.getType();

    //Your Code Goes Here...

    if(action.equals(Intent.ACTION_SEND) && type != null){
        if(type.startsWith("image/")){
            Uri mUri = mIntent.getParcelableExtra(Intent.EXTRA_STREAM);
            ImageModel imageModel = new ImageModel();
            imageModel.setName("Image 1");
            imageModel.setUri(mUri);

            data.add(imageModel);
        }
    }
    else if(action.equals(Intent.ACTION_SEND_MULTIPLE) && type != null){
        ArrayList<Uri> mUris = mIntent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        for(int i=0;i<mUris.size();i++){
            ImageModel m = new ImageModel();
            m.setName("Image "+ i);
            m.setUri(mUris.get((i)));
            data.add(m);
        }
    }
    else
    {
        Toast.makeText(this,"from outside",Toast.LENGTH_SHORT).show();
    }
}
Kishan Mevada
  • 662
  • 1
  • 6
  • 17