Hello,
Welcome to our Microsoft Q&A platform!
but after I choose a app to launch, the app I chosen tell me "can not find the file", Where am I doing wrong?
I create a txt file, then store it in the /data/user/0/com.companyname.app9/files/File.txt
, I use your code, then use Chrome to open it, I get the file cannot access. Then I find wo places need to be changed. I can open the test text file normally.
Firstly, you need to grand Read/Write Url flags in your Intent like following code, If you want your files could be opened by other application.
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
intent.AddFlags(ActivityFlags.GrantWriteUriPermission);
Second, I notice you used android.support.v4.content
in the <provider>
, If you set the target framework to Android 10 or later, you need to change it like following code. You can refer to this link about Android File Provider Setup
<application android:label="App7.Android" android:theme="@style/MainTheme">
<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"></meta-data>
</provider>
</application>
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.