安卓.如何确定onActivityResult()中的媒体文件类型? [英] Android. How to determine the type of media file in onActivityResult()?

查看:103
本文介绍了安卓.如何确定onActivityResult()中的媒体文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Gallery获得媒体文件.

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);

如何在onActivityResult()中确定媒体文件的类型?

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;
        }
    }
}

推荐答案

尝试一下:

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

这篇关于安卓.如何确定onActivityResult()中的媒体文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆