0

i'm trying to send multiple images from my DIRECTORY_PICTURES , using intents.. i have written the following code.. but when i click the button, it says "Unfortunately stopped"..i tried debugging, but haven't been able to.. any suggestions ??

case R.id.button5:
        File pictures = Environment
                .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        String[] listofpics = pictures.list();
        Uri uri = null;
        ArrayList <Uri> arraylist = new ArrayList<Uri>(); 
        for(String picture : listofpics){
            uri = Uri.parse("file://" + pictures.toString() + "/" + picture);
            arraylist.add(uri);
        }

        i = new Intent(Intent.ACTION_SEND_MULTIPLE);
        i.setType("image/*");
        i.putExtra(Intent.EXTRA_STREAM, arraylist);
        chooser = Intent.createChooser(i, "Send Images : ");
        startActivity(chooser);
        break;
    }

P.S. I tried putting the permissions as well..but still didnt work..

>                <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
>                <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
>                <uses-permission android:name="android.permission.INTERNET"/>

Logcat :

11-23 14:07:53.490: E/AndroidRuntime(12264): FATAL EXCEPTION: main
11-23 14:07:53.490: E/AndroidRuntime(12264): java.lang.IllegalStateException: Could not execute method of the activity
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.view.View$1.onClick(View.java:3599)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.view.View.performClick(View.java:4204)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.view.View$PerformClick.run(View.java:17355)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.os.Handler.handleCallback(Handler.java:725)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.os.Looper.loop(Looper.java:137)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.app.ActivityThread.main(ActivityThread.java:5041)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at java.lang.reflect.Method.invokeNative(Native Method)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at java.lang.reflect.Method.invoke(Method.java:511)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at dalvik.system.NativeStart.main(Native Method)
11-23 14:07:53.490: E/AndroidRuntime(12264): Caused by: java.lang.reflect.InvocationTargetException
11-23 14:07:53.490: E/AndroidRuntime(12264):    at java.lang.reflect.Method.invokeNative(Native Method)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at java.lang.reflect.Method.invoke(Method.java:511)
11-23 14:07:53.490: E/AndroidRuntime(12264):    at android.view.View$1.onClick(View.java:3594)
11-23 14:07:53.490: E/AndroidRuntime(12264):    ... 11 more
11-23 14:07:53.490: E/AndroidRuntime(12264): Caused by: java.lang.NullPointerException
11-23 14:07:53.490: E/AndroidRuntime(12264):    at com.example.interviewprep.Intents.launchStuff(Intents.java:80)
11-23 14:07:53.490: E/AndroidRuntime(12264):    ... 14 more

thanks !

rattlehead
  • 57
  • 9
  • i've edited it..please check.. – rattlehead Nov 23 '14 at 08:40
  • there is issue with ur declaration of R.id.button5: – KOTIOS Nov 23 '14 at 08:43
  • this is all i have done.. for button5.. i just put a tast in that button5, and it worked fine actually.. any other advice ? – rattlehead Nov 23 '14 at 08:55
  • inside case R.id.button5: just comment all code and just print a toast there and tel me if it crashed or not – KOTIOS Nov 23 '14 at 08:58
  • i just put a toast, and it didnt crash.. – rattlehead Nov 23 '14 at 09:02
  • ohh can u tell me what code is wriiten at this line ?-->com.example.interviewprep.Intents.launchStuff(Intents.java:80) – KOTIOS Nov 23 '14 at 09:23
  • line 80 : for(String picture : listofpics) – rattlehead Nov 23 '14 at 10:12
  • So `listofpics` is null. Add to your code `if (listofpics==null){Toast(... pictures.getAbsolutePath() ... does not contain files...); return}`. But still better check first if the directory exits. `if(!pictures.exists()){Toast(...); return;}`. – greenapps Nov 23 '14 at 10:59
  • yes i did.. i had a folder already in my phone memory called Pictures, with images in it. i dont know the reason, why it wasn't getting picked from there.. I just copied that folder(Pictures) into my SDCard and it worked.. and i used the same permissions i mentioned above.. Thanks for your time everyone ! – rattlehead Nov 23 '14 at 13:41

1 Answers1

0

you can try using this links for guiding your way :

link 1 - look on accepted answer.

1: Select Multiple Images Using GalleryView and link 2

but not getting Ans for which i m looking for .. but i have found alternative solution . Get all images from inbuilt Gallery and set it all our custom Gellery .. kindly check out this linkCustom Gallery with checkbox

i hope it will help you.

Credit to this post

Community
  • 1
  • 1
SacreDeveloper
  • 1,253
  • 1
  • 9
  • 16
  • Appreciate your response and thanks for those links.. but i'm still not getting what did i do wrong.. – rattlehead Nov 23 '14 at 09:15
  • you cannot send multiple / get images via android normal intents.. (if i remember right), thats why you need to use alternative option. – SacreDeveloper Nov 23 '14 at 09:25