Convert file uri to content uri

前端 未结 5 604
暗喜
暗喜 2020-12-06 05:44

i want to choose a file (via file chooser) from astro manager (in my case a *.pdf or *.doc) but the uri contains only the file path (\"sdcard/my_folder/test.pdf\"

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 06:21

    This works for me and what I use in my Share Folder app:

    1. Create a folder called xml under resources

    2. Add a file_paths.xml to it, with following line in it:

    
    
    1. Add a File provider authority in the manifest, as:
    
                   
    
    

    4.Transfer file to a different intent with 'content://' as follows:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //Required for Android 8+
    Uri data = FileProvider.getUriForFile(this, "com.dasmic.filebrowser.FileProvider", file);
    intent.setDataAndType(data, type);
    startActivity(intent);
    

提交回复
热议问题