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);
    }

    推荐使用第一种。

  • 相关阅读:
    一些我遇到前端方面的问题和解决方法
    Effective Objective-C 2.0学习记录(二)
    Effective Objective-C 2.0学习(一)
    加快Xcode运行速度
    JPA CriteriaBuilder的简单使用
    日志切分
    iOS并发,串行,异步,同步
    服务重启脚本
    简述http/https加密和认证方式
    nohup的使用
  • 原文地址:https://www.cnblogs.com/1925yiyi/p/10319489.html
Copyright © 2011-2022 走看看