java.lang.IllegalArgumentException: Failed to find configured root that contains /file:/ Ask Question

Course Queries Syllabus Queries 3 years ago

4.43K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago


I am trying to open the file downloaded by DownloadManager. I registered a BroadcastReceiverwith action DownloadManager.ACTION_DOWNLOAD_COMPLETE.

Here's the onReceive method of my receiver-

try {
    DownloadManager tag/dm">dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);

    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(downloadId);

    Cursor c = tag/dm">dm != null ? tag/dm">dm.query(query) : null;
    Log.d("Cursor", String.valueOf(c));
    String uri = null;
    if (c != null && c.moveToFirst()) {
        uri = c.getString(c.getColumnIndex("local_uri"));
    }
    Log.d("URI", uri);

    Intent open = new Intent(Intent.ACTION_VIEW);
    open.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

    //Get mime type
    String mimeType = "*/*";
    String tag/extension">extension = null;
    tag/extension">extension = MimeTypeMap.getFileExtensionFromUrl(uri);
    if (tag/extension">extension != null) {
        mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(tag/extension">extension);
    }

    //Set tag/data">data and start activity  
    open.setDataAndType(FileProvider.getUriForFile(getApplicationContext(), getPackageName() + ".provider", new File(Uri.parse(uri).getPath())), mimeType);    //It shows error at this line 
    startActivity(install);
} catch (Exception e) {
    e.printStackTrace();
}  

Here is the provider tag in my AndroidManifest.xml file -

<provider
    android:name=
                                                
0 views
0 shares

profilepic.png
manpreet 3 years ago

Replace new File(uri) with new File(Uri.parse(uri).getPath()) in your FileProvider.getUriForFile() call. The value that you get from local_uri appears to be a Uri, with a file scheme.

Also, depending upon the rest of the Uri, you may need to replace external-files-path with external-path.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum