Android无法打开相册查看视频
最近公司做了一个项目需要查看手机视频,在android 8的模拟器上正常。在android 5.1的模拟器下却报了一个错误:
Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.PICK dat=content://media/external/video/media
cmp=com.android.music/.VideoBrowserActivity } from ProcessRecord{1b308dad 5422:com.videoclipper.demo/u0a58} (pid=5422, uid=10058) not exported from uid 10036
讲道理不应该有权限问题的。因为target为21,而且api22没有运行时权限,android 8也可以正常运行。这个现象真的很莫名其妙啊。经过搜索找到了一种解决方法:原文
// contentId will have the video content id as given by Content Resolver
// In this nparticular application, contentId is retrieved from ListActivity with custom adapter
Uri contentUri = ContentUris.withAppendedId(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentId);
try {
Intent intent = new Intent(Intent.ACTION_VIEW, contentUri);
startActivity(intent);
}
catch (ActivityNotFoundException e) {//SecurityException 也可以
Toast.makeText(this, "Not Supported", Toast.LENGTH_SHORT).show();
}
要调用 Gallery browser 使用以下代码:
someMethod() {
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setType("video/*");
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == 1) && (resultCode == RESULT_OK) && (data != null)) {
Log.i("---------------------", data.getData().getEncodedPath());
mIntentFromGallery = data;
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.setType("video/*");
intent.setData(data.getData());
try
{
startActivity(intent);
}
catch(Exception e)
{
}
} else {
setResult(RESULT_CANCELED);
finish();
}
}
综合起来的解决方案就是:
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
intent.setDataAndType(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "video/*");
startActivityForResult(intent, REQUEST_CODEE_VIDEO);
关注公众号
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Android 沉浸式状态栏 以及 伪沉浸式状态栏
小菜最近在调整页面状态栏的效果,主要包括沉浸式状态栏和伪沉浸状态栏(同事唠嗑给定义的玩的)。 前段时间整理过一篇 Android 沉浸式状态栏的多种样式,现在小菜在稍微的补充一下,都是在日常应用中测试整理的。 非 Toolbar 标题栏 就小菜接触的项目中根据业务不同,不是所有的标题栏都是 Toolbar 标题栏样式,很多是自定义的标题栏样式,为了效果统一,小菜的解决方案是修改顶部状态栏的颜色为程序的主题色,戏称为伪沉浸式状态栏。 以下是小菜自己测试的最简单的标题栏样式: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <FrameLayout android:layout_w...
-
下一篇
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
最近要编译FFMPEG,但是一真报这个错,我用的是deepin系统。android studio 3.1.2。cmake,gcc,g++都已经安装了,但是编译就过不去,总是报这个错 CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage 很是恼火啊。最后找到了解决方案: 去掉build.gradle里ndk{} 里面的 'armeabi' 就好了。
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS关闭SELinux安全模块
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- Docker容器配置,解决镜像无法拉取问题
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7

微信收款码
支付宝收款码