Failed to open trivial text file with FileProvider

I'm crazy, I used the new Android FileProviderin the past, but I can’t get it to work with the (trivial) file just created in the Download folder.

In mine AsyncTask.onPostExecuteI call

Intent myIntent = new Intent(Intent.ACTION_VIEW, FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", output));
myIntent.setType("text/plain");
myIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(myIntent);

My FileProvider XML file is similar to this

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="Download" path="Download"/>
</paths>

In the Genymotion emulator, I always get by choosing Amaze Text Editor as the target application: enter image description here

So far I see the contents of the file using the HTML Viewer: enter image description here

I can not understand this behavior and fix what should be a trivial task, for example, to open a file with clear text using the requested text editor.

thanks a lot Nicola

0
1

, . - , Amaze, - Amaze, .

setType() : Uri Intent. setDataAndType(null, ...) ( ... - MIME). . , , Uri setType(), setDataAndType() Uri . Amaze, null Uri.

, , Uri -. , . , , FileNotFoundException, -, . , Android 8.1, SecurityException. , .

, , :

Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setDataAndType(FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", output), "text/plain");
myIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivity(myIntent);
+1

Source: https://habr.com/ru/post/1673542/


All Articles