0

I have an arrayList with URI's and i want an intent to open it with gallery.

This is what i have now:

public void btnChoosePhotosClick(View v){

    ArrayList<String> selectedItems = imageAdapter.getCheckedItems();
    Toast.makeText(MainActivity.this, "Total photos selected: "+selectedItems.size(), Toast.LENGTH_SHORT).show();
    Log.d(MainActivity.class.getSimpleName(), "Selected Items: " + selectedItems.toString());

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + selectedItems), "image/*");
    startActivity(intent);
}

But this just opens empty gallery with the text "no thumbnail"

GetCheckItems()

public ArrayList<String> getCheckedItems() {
        ArrayList<String> mTempArry = new ArrayList<String>();

        for(int i=0;i<mList.size();i++) {
            if(mSparseBooleanArray.get(i)) {
                mTempArry.add(mList.get(i));
            }
        }

        return mTempArry;
    }
Chimpanse
  • 250
  • 1
  • 5
  • 17

1 Answers1

1

Instead of Strings, try to get the Uri

// Instead of Strings, return the Uri of each file.
ArrayList<Uri> selectedItems = imageAdapter.getCheckedItems(); 

There is a method called: Uri.fromFile(file);

If you manage to pass the files Uri on your imageAdapter.getCheckedItems(); it should work.

Try this on your Intent:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setType("image/*"); /* All Image Types */
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, selectedItems);
startActivity(intent);
Joaquim Ley
  • 4,038
  • 2
  • 24
  • 42
  • i get this error: Error:(101, 15) error: method putParcelableArrayListExtra in class Intent cannot be applied to given types; required: String,ArrayList extends Parcelable> found: String,ArrayList reason: actual argument ArrayList cannot be converted to ArrayList extends Parcelable> by method invocation conversion – Chimpanse Sep 08 '14 at 18:15
  • Are you getting the files uri? You should pass the files and then use. Uri.getFromFile(file), Instead of Strings, get the all the files URI and pass an ArrayList selectedItems and it should work. – Joaquim Ley Sep 08 '14 at 18:31
  • Do you know any place i can see an example or how to do what you're talking about because i'm quite confused. – Chimpanse Sep 08 '14 at 18:36
  • try this: http://stackoverflow.com/questions/9550557/android-action-view-multiple-images – Joaquim Ley Sep 08 '14 at 18:37
  • show me your imageAdapter.getCheckedItems(); method – Joaquim Ley Sep 08 '14 at 18:39
  • added the get checkedItems to original post – Chimpanse Sep 08 '14 at 18:45