1

I have a problem that i want to select images and video from gallery in aNDROID i have used following codes but unsuccessful.

  1. setType("*/*);
  2. setType("video/*");
  3. setType("image/*");
  4. setType("image/* , video/*");
  5. setType("image/* video/*");
  6. Intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, 1);
  7. Intent i= new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); i.setType("*/*"); startActivityForResult(i, RESULT_LOAD_IMAGE);
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
kunwar abhishek
  • 91
  • 2
  • 3
  • 8

3 Answers3

9
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*,video/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);

you'll find more details at this question.

Community
  • 1
  • 1
Alaa Eldin
  • 2,178
  • 4
  • 21
  • 24
  • Hi Alaa, Its code is working in Activity only.. not for Fragment Class.. can u tell the way this code working in fragment class. – harikrishnan Oct 07 '15 at 13:47
1

The below code is working for me to load video in a fragment:

private void loadVideo(){
    Intent intent = new Intent();
    intent.setType("video/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Video"), LOAD_TESTING_VIDEO);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
       if (requestCode == LOAD_TESTING_VIDEO) {
           // Get the Video from data
           Uri selectedVideo = data.getData();
           String[] filePathColumn = {MediaStore.Video.Media.DATA};
           Cursor cursor = getActivity().getContentResolver().query(selectedVideo, filePathColumn, null, null, null);
           if (cursor != null) {
               cursor.moveToFirst();
               int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
               mediaPath1 = cursor.getString(columnIndex);
               //uptestVideoName is a EditText
               upTestVideoName.setText(mediaPath1);
               cursor.close();
           }
        }
    }
}
Praveen
  • 2,137
  • 1
  • 18
  • 21
1
    case SELECT_IMAGE:
            intent = createGetFileIntent(SELECT_IMAGE, "image/*");
            startForResult(intent, 0);
            break;
        case SELECT_VIDEO:
            intent = createGetFileIntent(SELECT_VIDEO, "video/*");
            startForResult(intent, 1);
            break;



    private Intent createGetFileIntent(int fileType,
                                   String mimeType) {
    Intent intent = new Intent(Intent.ACTION_PICK);

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    }

    intent.setType(mimeType);

    switch (fileType) {
        case SELECT_IMAGE:
            intent = Intent.createChooser(intent, getString(R.string.title_select_image));
            break;
        case SELECT_VIDEO:
            intent = Intent.createChooser(intent, getString(R.string.title_select_video));
            break;
        default:
            break;
    }

    return intent;
}
Vaibhavi
  • 71
  • 4