• android 7.0 调用系统相机崩溃的解决方案(非谷歌官方推荐)


    解决方案:

    1、(推荐)7.0之后你的app就算有权限,给出一个URI之后手机也认为你没有权限。

    不用修改原有代码,在Application的oncreate方法中:(或者直接放在调用相机的activity的onCreate方法中)

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
         StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
         StrictMode.setVmPolicy(builder.build());
       }
    

     2、(强烈不推荐)在调用相机的时候添加7.0系统的判断(谷歌官方推荐的,但是本人强烈不推荐,坑太多)

    /*获取当前系统的android版本号*/
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    Log.e("currentapiVersion","currentapiVersion====>"+currentapiVersion);
    if (currentapiVersion<24){
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(pathFile));
        startActivityForResult(intent, TAKE_PICTURE);
    }else {
        ContentValues contentValues = new ContentValues(1);
        contentValues.put(MediaStore.Images.Media.DATA, pathFile.getAbsolutePath());
        Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, TAKE_PICTURE);
    }

    推荐使用第一种。

  • 相关阅读:
    opatch卸载weblogic12.1.3.0补丁
    linux weblogic12.1.3.0卸载过程
    pip install xxxx报错(一大堆红色exception)【解决】
    (CVE-2017-10271)weblogic12.1.3.0漏洞测试与打补丁过程
    linux 安装weblogic12.1.3.0步骤
    python基础实战之猜年龄游戏
    python基础小结
    计算机基础
    面向对象基础
    数据库总结
  • 原文地址:https://www.cnblogs.com/1925yiyi/p/10319489.html
Copyright © 2020-2023  润新知