zoukankan      html  css  js  c++  java
  • 拍照,裁剪功能在Android 7.0上的问题。

    FileProvider

    1. 在manifest文件中配置FileProvider路径。

    <provider
    android:name="android.support.v4.content.FileProvider"
    android:authorities="${applicationId}.provider"
    android:exported="false"
    android:grantUriPermissions="true"
    tools:replace="name,authorities,exported,grantUriPermissions">
    <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/provider_paths"
    tools:replace="name,resource"/>
    </provider>

    tools:replace 是 合并xml 时,替换相应属性。

    provider_paths:
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-cache-path name="my_images" path="images" />
    </paths>

    2.  用android 25 上 用 FileProvider.getUriForFile 生成uri, 以下用Uri.parse生成

    Uri photoUri;
    if(Build.VERSION.SDK_INT>Build.VERSION_CODES.M){
    File file;
    file = new File(mCachePic);
    photoUri = FileProvider.getUriForFile(
    act,
    act.getPackageName() + ".provider",
    file);
    }else{
    photoUri = Uri.parse(mCachePic);
    }

    3. 添加权限
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

    4. crop时, outputUri 要用Uri.parse(path);
    Intent intent = new Intent("com.android.camera.action.CROP");
    // 照片URL地址
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("crop", "true");
    intent.putExtra("aspectX", aspectX);
    intent.putExtra("aspectY", aspectY);
    intent.putExtra("outputX", w);
    intent.putExtra("outputY", h);
    intent.putExtra("scale", true);//黑边
    intent.putExtra("scaleUpIfNeeded", true);//黑边
    // 输出路径
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
  • 相关阅读:
    AHK的OnMessage
    VBA7种文档遍历法
    Excel VBA 找出选定范围不重复值和重复值
    Excel图片调整大小
    Excel信息提取之二
    Excel不同工作簿之间提取信息
    VBA7种遍历方法
    Exce信息提取
    php笔记之文件载入和异常处理
    php笔记之流程控制
  • 原文地址:https://www.cnblogs.com/songsh/p/7110458.html
Copyright © 2011-2022 走看看