当前位置: 移动技术网 > IT编程>移动开发>Android > Android项目实战(四十九):Andoird 7.0+相机适配

Android项目实战(四十九):Andoird 7.0+相机适配

2018年08月23日  | 移动技术网IT编程  | 我要评论

要过好日子演员表,赛场失禁的尴尬瞬间,娱乐休闲游戏

解决方案类似:

android项目实战(四十):andoird 7.0+ 安装apk适配

 

解决方法:

 

一、在androidmanifest.xml 文件中添加 四大组件之一的 <provider>

    

复制代码
 <!-- 适配7.0 apk安装 -->
        <provider
            android:name="android.support.v4.content.fileprovider"
            android:authorities="你的包名.fileprovider" 
            android:granturipermissions="true"
            android:exported="false">
            <!--元数据-->
            <meta-data
                android:name="android.support.file_provider_paths"
                android:resource="@xml/file_paths" />
        </provider>
复制代码

 

   注意这里的  android :authorities 属性的值 中的 com.xxx.xxxx 是你的包名,不可随意填写

 

二、res 目录下 建一个xml 文件,并新建xml文件file_paths.xml 

    注意文件名要和第一步中的 resource 属性的值一致 

    内容为:

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <external-path path="." name="download"/>
</paths>

 

 

三、根据机型的android系统级别执行不同的安装调用相机intent代码

     注意,根据系统版本执行不同代码,7.0以下调用7.0+的代码会报错,7.0+的调用7.0以下的会报错。

 

      file camerafile = new file(pathutil.getinstance().getimagepath(), 
                + system.currenttimemillis() + ".jpg");
 
        intent intent = new intent(mediastore.action_image_capture);
        if (build.version.sdk_int >= build.version_codes.n){
            intent.putextra(mediastore.extra_output,
                    fileprovider.geturiforfile(getactivity(),"你的包名.fileprovider", camerafile));
        }else {
            intent.putextra(mediastore.extra_output, uri.fromfile(camerafile));
        }
        startactivityforresult(intent, request_code_camera);

 

  

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网