Skip to content Skip to sidebar Skip to footer

Android: Fileprovider "failed To Find Configured Root"

I'm trying to use FileProvider to share a SQL database file via email. Error: java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.colum

Solution 1:

Solved (Thanks @CommonsWare). FileProvider cannot access the SQL database file because it is in the databases directory. I just copied the file from the databases dir to the files dir (so that FileProvider can get to it), added permissions, attached it to email, and then deleted the db from the files dir when email sent with the start and onActivityForResult() methods.

My Java looks like this now:

//this copies the .db file from dabases dir where FileProvider cannot access it and moves it to files dirFilebooger= copyFileToFilesDir("testresults.db");
    Log.d("LOG PRINT SHARE DB", "we found a booger, Here it is: " + booger.toString());

    UricontentUri= FileProvider.getUriForFile(this, "com.columbiawestengineering.columbiawest", booger);
    Log.d("LOG PRINT SHARE DB", "contentUri got: here is contentUri: " + contentUri.toString());

and here is what I did to copy the file:

private File copyFileToFilesDir(String fileName) {
    Filefile=null;
    StringnewPath= getFileStreamPath("").toString();
    Log.d("LOG PRINT SHARE DB", "newPath found, Here is string: " + newPath);
    StringoldPath= getDatabasePath("testresults.db").toString();
    Log.d("LOG PRINT SHARE DB", "oldPath found, Her is string: " + oldPath);
    try {
        Filef=newFile(newPath);
        f.mkdirs();
        FileInputStreamfin=newFileInputStream(oldPath);
        FileOutputStreamfos=newFileOutputStream(newPath + "/" + fileName);
        byte[] buffer = newbyte[1024];
        intlen1=0;
        while ((len1 = fin.read(buffer)) != -1) {
            fos.write(buffer, 0, len1);
        }
        fin.close();
        fos.close();
        file = newFile(newPath + "/" + fileName);
        if (file.exists())
            return file;
    } catch (Exception e) {

    }
    returnnull;
}

Solution 2:

Also, Logcat for goob shows the correct db location:

Yes, but that's not where <files-path> points to. Given that database path, the equivalent getFilesDir() would be:

/data/data/com.columbiawestengineering.columbiawest/files

Hence, your database is not inside the getFilesDir() directory, which is what <files-path> uses, which is why FileProvider is not happy. FileProvider does not support sharing content from the database directory.

Post a Comment for "Android: Fileprovider "failed To Find Configured Root""