Android taking picture with FileProvider

后端 未结 2 1239
渐次进展
渐次进展 2020-12-20 20:03

I\'m taking a picture on Android Nougat with FileProvider, that\'s my code



        
相关标签:
2条回答
  • 2020-12-20 21:06

    if androidx was used in your project, you need replace dot(.) to slash(/).

    <!--别用. 不然在androidx上面有问题-->
    <external-path name="sdcard" path="/" /> 
    

    works for me great!

    0 讨论(0)
  • 2020-12-20 21:07

    The main thing to get camera and gallery URI working is provider paths.

    you need to create a provider_paths.xml to /res/xml/ dir

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
    </paths>
    

    In your manifest file add this lines between

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

    One more thing, I've found that we need to set vmPolicy in Application class like this

    @Override
    public void onCreate() {
        super.onCreate();
       //Allowing Strict mode policy for Nougat support
       StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
       StrictMode.setVmPolicy(builder.build());
    }
    

    Double check your camera and external storage permission in manifest file and there you go with nougat URI.

    For more details check this link : Android N FileUriExposedException

    0 讨论(0)
提交回复
热议问题