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

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 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 2 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.