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);
  • 相关阅读:
    解决Shiro在Tomcat重启之后丢失登录信息
    代码安全审计大全
    解决Spring Boot打包war部署到Tomcat出现Could not open ServletContext resource
    weblogic12 重装记录
    【Spring】事物和锁及回滚异常类型
    【Spring】thymeleaf + SpringMVC局部刷新
    【Spring】@ModelAttribute三种使用场景
    Java Optional
    JAVA lambda
    最短时间(最短路+思维)
  • 原文地址:https://www.cnblogs.com/songsh/p/7110458.html
Copyright © 2011-2022 走看看