Quote:
Originally Posted by chaley
You say that it works in some cases. Yes, it does, because the current releases of CC "target" Android 6. This causes Android 7 & up to run in "compatibility mode" so that passing files works...
If I were still developing CC I would under no circumstance code around vendor-specific strangeness in this area to try to make passing files work on some devices when targeting Android 8+. There lies madness. Instead I would (attempt) to keep the current behavior for Android 6 while making Android 7+ pass copies of the books (content providers)...
|
I'm sorry for bothering you again, chaley. Yesterday I installed the play store version of Moon Reader, built with targetSdk 28 and is still able to pass a file scheme to other apps without showing the FileUriExposedException on my device.
I'm aware that emulators can open file schemes without problems, following this example:
Code:
adb shell
cd /sdcard
echo "hello world" > test.txt
am start -a android.intent.action.VIEW -t 'text/html' -d 'file:///sdcard/test.txt'
It could be because shell tools are not under a certain domain sandbox and can expose file uris without hussle. But again I can reproduce on my huawei with both am and with modern apps built against latest levels. So I'm guessing that the following scheme will work even on targetSdk >= 24.
Code:
try {
File file = new File("/sdcard", "test.txt"; // lets assume file exists here...
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/plain");
startActivity(intent)
} catch(FileUriExposedException e) {
// ooohhh, no fun. try the content provider approach instead.
}