Android How to determine media type in onActivityResult ()?

I get a media file from the 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 media type 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;
        }
    }
}
+2
source share
1 answer

Try the following:

ContentResolver cr = this.getContentResolver();
String mime = cr.getType(uri);
+6
source

Source: https://habr.com/ru/post/1621930/


All Articles