How to select video from gallery through intent?
Step 1: Declare the variables on the activity from where you want to hit the intent
int SELECT_VIDEO_REQUEST=100;
String selectedVideoPath;
Step 2: Selecting Video from gallery by intent hit
public void selectVideoFromGallery()
{
Intent intent;
if(android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
{
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
}
else
{
intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.INTERNAL_CONTENT_URI);
}
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
startActivityForResult(intent,SELECT_VIDEO_REQUEST);
}
Step3: OnActivity result you can get the path of the video you have just selected*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == SELECT_VIDEO_REQUEST && resultCode == RESULT_OK)
{
if(data.getData()!=null)
{
String selectedVideoPath = getPath(data.getData(),activity );
}
else
{
Toast.makeText(getApplicationContext(), "Failed to select video" , Toast.LENGTH_LONG).show();
}
}
}
2 Comment(s)