use*_*799 2 android gallery android-intent
我从Gallery获取媒体文件.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*,video/*,audio/*");
startActivityForResult(Intent.createChooser(intent, "Select Media"), CameraUtils.REQUEST_GALLERY);
Run Code Online (Sandbox Code Playgroud)
如何在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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
Pre*_*ola 12
试试这个:
ContentResolver cr = this.getContentResolver();
String mime = cr.getType(uri);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1939 次 |
| 最近记录: |