Android 7.0, take a picture error

Source: Internet
Author: User

For Android 7.0-oriented apps, the Android framework enforces an StrictMode API policy that prohibits exposing URIs outside your app file:// . If a intent that contains a file URI leaves your app, the app fails with an FileUriExposedException exception.

To share files between apps, you should send a content:// URI and grant temporary access to the URI. The simplest way to make this authorization is to use a FileProvider class.

Workaround:

First add <provider> in the <application> tab of Androidmanifest.xml

       <!--file Sharing-        <provider            android:name= "Android.support.v4.content.FileProvider"             android:authorities= "${application_id}.provider"            android:exported= "false"             Android:granturipermissions= "true" >            <meta-data                android:name= " Android.support.FILE_PROVIDER_PATHS "                android:resource=" @xml/provider_paths "/>        </ Provider>

Next, create the XML subfolder under the Res folder (if it already exists, ignore it) and new file Provider_paths.xml

The contents are as follows

<?xml version= "1.0" encoding= "Utf-8"?><paths>    <external-path path= "." Name= "External_files"/ ></paths>

Next, when jumping, the URI passed in is no longer used

Uri.fromfile (tmpfile);

Instead, use Fileprovider's Geturiforfile () method to get

    New Intent (mediastore.action_image_capture);     NULL , Storageutils.getimagedir (context));     = Fileprovider.geturiforfile (context,            + ". Provider", tempfile);    Intent.putextra (Mediastore.extra_output, Imguri);    Startactivityforresult (Intent, request_take);

Reference address

Android 7.0, take a picture error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.