Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

android - provider does not have permission to content when open intent camera

I have a basic :app module. and there is the :camera module. In the camera module, I open the native camera using intent. MediaStore.ACTION_IMAGE_CAPTURE

but the camera doesn't work, as I get an error

UID 10388 does not have permission to content://com.example.android.provider/attachment_file/Android/media/com.example.android.dev/some_name.jpg [user 0]

here's mine provider AndroidManifest in app:

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

if you change the android:authorities on "com.example.android.provider" then the camera works. But the app stops being installed on the phone due to other build variants installed

question from:https://stackoverflow.com/questions/65924025/provider-does-not-have-permission-to-content-when-open-intent-camera

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The Camera permission protected level is dangerous.

so you have to ask the user for this permission in runtime.

here you can see the permissions level such as camera permission: https://developer.android.com/reference/android/Manifest.permission#CAMERA

And look in the Android developer training site examples how exactly you ask this permissions. The all information is their: https://developer.android.com/training/permissions/requesting

The code should look like that:

if (ContextCompat.checkSelfPermission(
        CONTEXT, Manifest.permission.REQUESTED_PERMISSION) ==
        PackageManager.PERMISSION_GRANTED) {
    // You can use the API that requires the permission.
    performAction(...);
} else if (shouldShowRequestPermissionRationale(...)) {
    // In an educational UI, explain to the user why your app requires this
    // permission for a specific feature to behave as expected. In this UI,
    // include a "cancel" or "no thanks" button that allows the user to
    // continue using your app without granting the permission.
    showInContextUI(...);
} else {
    // You can directly ask for the permission.
    // The registered ActivityResultCallback gets the result of this request.
    requestPermissionLauncher.launch(
            Manifest.permission.REQUESTED_PERMISSION);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...