vxh.viet
4/6/2016 - 5:54 AM

Open gallery and choose video

Open gallery and choose video

Source: StackOverflow

Question: Open gallery and choose video.

Answer:

Use this for the picking Intent:

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("video/*");
startActivityForResult(intent, REQUEST_TAKE_GALLERY_VIDEO);

Receive the result:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) {
                Uri selectedVideoUri = data.getData();
                String selectedVideoPath = getPath(selectedVideoUri);
            }
        }
    }