Skip to content

Instantly share code, notes, and snippets.

@NsAveek
Last active November 9, 2018 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NsAveek/007a957f0dfd3809d6962e59d30eff05 to your computer and use it in GitHub Desktop.
Save NsAveek/007a957f0dfd3809d6962e59d30eff05 to your computer and use it in GitHub Desktop.
Select Video Using Intent
public void getFile(View view) {
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_CODE_PICKER);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
try {
String fileName = "test.mp4";
InputStream inputStream=contentResolver.openInputStream(uri)
File filesDir = getApplicationContext().getDir("Dummy", Context.MODE_PRIVATE);
filesDir.mkdirs();// if not created
File newFile = new File(filesDir, "test.mp4")
FileUtils.copyInputStreamToFile(inputStream, newFile)
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment