Home > Mobile >  Android Q jump to Download directory
Android Q jump to Download directory

Time:12-15

 
//download button
DownloadPdf2LocalFile ((fp) - & gt; {
The File File=new File (fp);
CopyFile2PublicDownload (file);
The d (TAG, "getParentFile:" + file. GetParentFile () getPath ());

Intent Intent=new Intent (Intent. ACTION_GET_CONTENT);
Uri Uri=FileProvider. GetUriForFile (getApplicationContext (), "com. Twx.n poc. Voicejob. FileProvider", the file. The getParentFile ());
Intent. AddCategory (intent. CATEGORY_OPENABLE);
Intent. AddFlags (intent. FLAG_GRANT_READ_URI_PERMISSION);
Intent. SetDataAndType (uri, "*/*");
startActivity(intent);
});



Code above is to copy files to the Download directory, then open the intent for the user to see, the results did not jump to Download directory
On the Internet to see a lot of posts are not resolved, especially bosses, please open ^_^

CodePudding user response:

The official documentation to find such a description: https://developer.android.com/training/data-storage/shared/documents-files#grant-access-directory

 
Public void openDirectory uriToLoad (Uri) {
//Choose a directory using the system 's file picker.
Intent Intent=new Intent (Intent. ACTION_OPEN_DOCUMENT_TREE);

//dojo.provide read access to files and sub - directories in the user - selected
//directory.
Intent. AddFlags (intent. FLAG_GRANT_READ_URI_PERMISSION);

//Optionally, specify a URI for the directory that should be the opened in
//the system file picker when it loads.
Intent. PutExtra (DocumentsContract EXTRA_INITIAL_URI, uriToLoad);

StartActivityForResult (intent, your request - code);
}


Applied to the code
 
//Intent Intent=new Intent (Intent. ACTION_GET_CONTENT);
//Uri Uri=FileProvider. GetUriForFile (getApplicationContext (), "com. Twx.n poc. Voicejob. FileProvider", the file. The getParentFile ());
//intent. AddCategory (intent. CATEGORY_OPENABLE);
//intent. AddFlags (intent. FLAG_GRANT_READ_URI_PERMISSION);
//intent. SetDataAndType (uri, "*/*");
//startActivity (intent);
Intent Intent=new Intent (Intent. ACTION_OPEN_DOCUMENT_TREE);
Intent. AddFlags (intent. FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);


Can be normal open,

Do not know to have compatibility problems
  • Related