Last active
November 9, 2018 10:09
-
-
Save NsAveek/007a957f0dfd3809d6962e59d30eff05 to your computer and use it in GitHub Desktop.
Select Video Using Intent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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