Android. How To Determine The Type Of Media File In Onactivityresult()?
I get media file from Gallery. Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType('image/*,video/*,audio/*'); startActivityForResult(Inte
Solution 1:
Try this:
ContentResolvercr=this.getContentResolver();
Stringmime= cr.getType(uri);
Solution 2:
Just for reference, in Kotlin we can create an extension function for this.
fun Activity.getMimeType(uri:Uri?):String?{
this.let {
val cr: ContentResolver = it.contentResolver
if (uri == null) returnnullreturn cr.getType(uri)?:null
}
}
Feel free to replace nulls with empty String or something. but this works fines!
Post a Comment for "Android. How To Determine The Type Of Media File In Onactivityresult()?"