老规矩先上图,注:我这个是其他类型设备的样式图,小米也一样的


由于小米手机可能对很多地方不见让,当然对调用系统相机时也跟其他设备不太一

样,一般情况下他都是底下弹出一个框,选取是否进入相册或者文件夹


下面就来贴一下代码

这是在选取相册选取视频的页面

                      if(PhoneInfo.isMIUI()){//是否是小米设备,是的话用到弹窗选取入口的方法去选取视频Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"video/*");startActivityForResult(Intent.createChooser(intent, "选择要导入的视频"), REQUEST_CODE_PICK);}else{//直接跳到系统相册去选取视频Intent intent = new Intent();if (Build.VERSION.SDK_INT < 19) {intent.setAction(Intent.ACTION_GET_CONTENT);intent.setType("video/*");} else {intent.setAction(Intent.ACTION_OPEN_DOCUMENT);intent.addCategory(Intent.CATEGORY_OPENABLE);intent.setType("video/*");}startActivityForResult(Intent.createChooser(intent, "选择要导入的视频"), REQUEST_CODE_PICK);}

我们写一下在相册选取视频之后的回调

@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == REQUEST_CODE_PICK && resultCode == RESULT_OK) {//从相册选取视频String videoPath = GetPathFromUri.getPath(this, data.getData());initVideo(videoPath);}}

在这里我把获取路径封装成了一个类,贴一下这个类的代吗

public class GetPathFromUri {@SuppressLint("NewApi")public static String getPath(final Context context, final Uri uri) {final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;// DocumentProviderif (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {// ExternalStorageProviderif (isExternalStorageDocument(uri)) {final String docId = DocumentsContract.getDocumentId(uri);final String[] split = docId.split(":");final String type = split[0];if ("primary".equalsIgnoreCase(type)) {return Environment.getExternalStorageDirectory() + "/" + split[1];}// TODO handle non-primary volumes}// DownloadsProviderelse if (isDownloadsDocument(uri)) {final String id = DocumentsContract.getDocumentId(uri);final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));return getDataColumn(context, contentUri, null, null);}// MediaProviderelse if (isMediaDocument(uri)) {final String docId = DocumentsContract.getDocumentId(uri);final String[] split = docId.split(":");final String type = split[0];Uri contentUri = null;if ("image".equals(type)) {contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;} else if ("video".equals(type)) {contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;} else if ("audio".equals(type)) {contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;}final String selection = "_id=?";final String[] selectionArgs = new String[]{split[1]};return getDataColumn(context, contentUri, selection, selectionArgs);}}// MediaStore (and general)else if ("content".equalsIgnoreCase(uri.getScheme())) {return getDataColumn(context, uri, null, null);}// Fileelse if ("file".equalsIgnoreCase(uri.getScheme())) {return uri.getPath();}return null;}/*** Get the value of the data column for this Uri. This is useful for* MediaStore Uris, and other file-based ContentProviders.** @param context       The context.* @param uri           The Uri to query.* @param selection     (Optional) Filter used in the query.* @param selectionArgs (Optional) Selection arguments used in the query.* @return The value of the _data column, which is typically a file path.*/public static String getDataColumn(Context context, Uri uri, String selection,String[] selectionArgs) {Cursor cursor = null;final String column = "_data";final String[] projection = {column};try {cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,null);if (cursor != null && cursor.moveToFirst()) {final int column_index = cursor.getColumnIndexOrThrow(column);return cursor.getString(column_index);}} finally {if (cursor != null)cursor.close();}return null;}/*** @param uri The Uri to check.* @return Whether the Uri authority is ExternalStorageProvider.*/public static boolean isExternalStorageDocument(Uri uri) {return "com.android.externalstorage.documents".equals(uri.getAuthority());}/*** @param uri The Uri to check.* @return Whether the Uri authority is DownloadsProvider.*/public static boolean isDownloadsDocument(Uri uri) {return "com.android.providers.downloads.documents".equals(uri.getAuthority());}/*** @param uri The Uri to check.* @return Whether the Uri authority is MediaProvider.*/public static boolean isMediaDocument(Uri uri) {return "com.android.providers.media.documents".equals(uri.getAuthority());}
}


我在这里判断了是否是小米手机,判断识别是否是小米设备可以参考我的另一篇博客

Android 判断手机设备是否是小米设备,是因为我目前遇到的是小米设备会有这种问

题需要处理,其他手机如果用这种方法的话可能会多此一举了,具体也是看需求了,我们看下如果其他手机用这种方法的情况下的效果图.




Android 调用系统相册选取视频,过滤视频(兼容小米)相关推荐

  1. Android调用系统相册、拍照以及裁剪最简单的实现(兼容7.0)

    这里我只实现功能,具体Android 7.0 的一些细节参考 http://blog.csdn.net/lmj623565791/article/details/72859156 具体步骤: 一.在清 ...

  2. android+代码调用+相册+小米,Android调用系统相册选择图片,支持小米4云相册

    用小米4调用系统相册选择照片时,如果云相册功能开启的话.云相册中的图片也会显示在选择列表中.经过测试,选择到云相册中的图片的话,uri的scheme是file,而不再试content.本文支持云相册的 ...

  3. android 调用相册功能吗,Android调用系统相册选择图片,支持小米4云相册

    用小米4调用系统相册选择照片时,如果云相册功能开启的话.云相册中的图片也会显示在选择列表中.经过测试,选择到云相册中的图片的话,uri的scheme是file,而不再试content.本文支持云相册的 ...

  4. android 调用 系统 相机 摄像机 拍照 拍视频

    主要内容如下: 系统现有相机应用的调用 系统现有相机拍摄照片 获取系统现有相机拍摄的图片 系统现有相机拍摄图片Demo 系统现有相机拍摄视频 系统现有相机拍摄视频Demo 系统现有相机应用的调用 对于 ...

  5. android调用系统相册将图片复制到指定目录下并显示复制进度

    最近在做一个类似文件管理器,app是采用本地数据库模拟目录的方式,管理与其手机储存对应的存储文件.那么需求来了,需要在app中添加一张从本地相册中选出来的照片,并将照片复制到自己app指定的目录下.这 ...

  6. 学习笔记之Android调用系统相册选择图片

    文章目录 前言 使用步骤 小结 参考资料 前言 在相册里选择图片上传也是很常见的功能了例如微信朋友圈等等.但是他们是自定义的选择器,可以选择多张图片并修改.这里我们讲一个最简单的:调用系统的相册选择一 ...

  7. android调用系统相册打开图片不显示,【报Bug】打开相册,不显示图片,选中图片后,app会崩溃...

    产品分类: uniapp/App PC开发环境操作系统: Mac PC开发环境操作系统版本号: 10 HBuilderX类型: 正式 HBuilderX版本号: 2.8.8 手机系统: Android ...

  8. android 实现自动拍照,Android:调用系统相机实现拍照+裁切(兼容7.0以上系统)

    android.jpg 前言 在平时的工作中,我们会经常遇到这样的需求:比如更改用户头像,我们就需要打开相机或相册,选择照片后进行裁剪,最后上传给后台... 相信这样的功能对小伙伴们来说可能早已司空见 ...

  9. Android 调用系统相机拍照和录制视频,保存照片和视频

    1.申请权限 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ...

最新文章

  1. 机器学习之支持向量机SVM之python实现ROC曲线绘制(二分类和多分类)
  2. CVPR 2021 | 微软提出解构式关键点回归, 刷新COCO自底向上多人姿态检测记录!...
  3. 小米A3真机开箱照片曝光:水滴屏+后置三摄
  4. aix linux ftp,在AIX下安装配置FTP服务器
  5. sqlite 无符号32_C语言的32个关键字
  6. php异步上传,php中通过Ajax如何实现异步文件上传的代码实例
  7. 手机客户端应用功能测试方法总结
  8. SAP系统如何打NOTE?
  9. 计算机办公自动化试题及答案,计算机等级考试,办公自动化考试试题(三)
  10. icem密度盒怎么设置_ICEM-自动体网格生成[精].ppt
  11. 手动挡五个档位示意图_小型C1手动挡汽车档位分布示意图
  12. 把握新航道,CSDN智能汽车技术路线图正式发布
  13. 基于单片机的数字频率计设计
  14. 思维导图怎么做计划的简单高效绘制方法
  15. wold文档直接转html文件乱码,打开WORD文档,发现它全是乱码,有时会出现“文件转换”窗口,让您选择编码. 如何处理?...
  16. 清华领军计划计算机试题,清华大学2017年自主招生领军计划笔试真题
  17. 2018年4月5日腾讯考试感想
  18. python引入op模块 实现游戏后台挂机 阴阳师
  19. 程序员能成为自由职业者吗?
  20. gdb+openocd+stlink调试MCU

热门文章

  1. Snovio软件怎么用?请看这篇邮件群发平台使用指南
  2. 自动驾驶中激光雷达如何检测障碍物
  3. PHP之linux(一)linux基础
  4. Bulldog2 渗透测试
  5. python写网络爬虫微博用户发布的视频
  6. html5手机电商网页设计代码_一部手机,万物皆可复制粘贴,这位兼职写代码的设计师将AR玩出了新高度...
  7. HBuilder 使用教程
  8. Android使用字体代替图标
  9. 行业报告归档 2018.3.28
  10. 视频格式那么多,MP4/RMVB/MKV/AVI 等,这些视频格式与编码压缩标准 mpeg4,H.264.H.265 等有什么关系?...