zoukankan      html  css  js  c++  java
  • 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);
    }

    推荐使用第一种。

  • 相关阅读:
    Beyond Compare同步功能简介
    CorelDRAW中如何制作表格
    如何解决CorelDRAW中尖突问题
    LCS 最长公共子序列
    Java容器部分用法
    数论知识简易总结
    操作系统的运行环境 中断与有异常
    OS的发展和分类
    操作系统的基本概念
    搭建神经网络的八股
  • 原文地址:https://www.cnblogs.com/1925yiyi/p/10319489.html
Copyright © 2011-2022 走看看