I get media file from Gallery.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*,video/*,audio/*");
startActivityForResult(Intent.createChooser(intent, "Select Media"), CameraUtils.REQUEST_GALLERY);
How to determine the type of media file in onActivityResult()?
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case CameraUtils.REQUEST_GALLERY:
Uri uri = data.getData();
//what type of media file?
break;
}
}
}
Try this:
ContentResolver cr = this.getContentResolver();
String mime = cr.getType(uri);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With