Intents on Android using API 26 to open PDF documents.
The Google Play store recently updated its requirements, so new apps were submitted with an API level of 26 as the target. While this was relatively simple to accomplish by updating the AndroidManifest.Template, the transition to the newer API altered the behavior of my application.
I used to download a file to the CachePath and then share it to a public folder before the update. I’d then obtain a URI for the public folder path file and share it using Intents. This no longer worked after the update. After doing some research, I discovered that this was due to changes in the Android security system, which make a lot of sense. Instead of sharing the file outside of the application, you now provide temporary access to it through the Intent. To accomplish this, you must first create a Provider (via XML) and then programmatically provide the path as a ‘content:/’ URI, set flags to allow read / write access via the intent, and share it.
In this post, we’ll show you a video that shows how to achieve this and demos the working code. To help, below are some of the XML blocks you will need along the way.
Add this to the AndroidManifest.template in the source code root folder, before the </application> tag. This is then used to build all Android apps.
Create a fileprovider.xml (or whatever file name you set in android:resource when declaring the provider).
<?xml version="1.0" encoding="utf-8"?>
<cache-path name="bbresources" path="bbresources/"/>
More flags and details for Provider Files can be found in the Android documentation