Click here to Skip to main content
16,020,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Trying to take a photo using "cameraIntent" (with MediaStore.EXTRA_OUTPUT and a URI). To facilitate secure sharing by creating a content://uri instead of a file:///uri, and have secure permissions I use "FileProvider.getUriForFile" and this is returning "Failed to find configured root that contains "/CL-Shopping.jpg"

Here's the steps I have taken.
1. Android Manifest... (Inside the application tag of course)
<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/provider_paths" />
</provider>

2. From the above we need provider_paths...
(Here I have tried "external-path" AND "external-files-path" AND "files-path"
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path
        name="files"
        path="/"/>
</paths>


3. Then - I attempt to get the URI...
try {
    val fName = "CL-$lName-$item.jpg"
    val dir = ""
    val newFile = File(dir, fName)
    val auth = BuildConfig.APPLICATION_ID + ".provider"
    val fUri = FileProvider.getUriForFile(context!!,  auth, newFile)

    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fUri)
    startActivityForResult(cameraIntent, 1001)
}
catch(e: Exception){
    val x=""
    val y=""
}


Breakpoint on the exception gives.
java.lang.IllegalArgumentException:
Failed to find configured root that contains /CL-Shopping-Potato Sticks.jpg

Obviously that's my filename and obviously it can't find the directory that
it's supposed to be in.

With a breakpoint on the getUriForFile, I can see that the variable "auth"
does have the application provider full name "com.example.missioncontroller.provider"

Please could anyone advise - thanks

What I have tried:

Have tried adding directory "files" which is seen as a directory under the com.example.missioncontroller directory...
Have tried several variants in the provider_paths file (all individually)
<files-path>
<external-path>
<external-files-path>
Posted
Comments
David Crow 9-May-23 11:07am    
Are you simply trying to get the full path to the picture you just took with the camera?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900