• 拍照,裁剪功能在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);
  • 相关阅读:
    053-606
    053-605
    1019 General Palindromic Number (20分)
    1208. 翻硬币
    754. 平方矩阵 II
    1346. 回文平方
    680. 剪绳子
    1227. 分巧克力
    756. 蛇形矩阵
    429. 奖学金
  • 原文地址:https://www.cnblogs.com/songsh/p/7110458.html
Copyright © 2020-2023  润新知