Android Question Opening PDF file with fileprovider is not working for all devices

Zak Petr

Member
Licensed User
Hi,

I use this code for opening pdf file.

open pdf file:
If File.Exists(File.DirInternal, inp_filename) = True Then
                    
            FProvider.Initialize
            
            File.Copy(File.Dirinternal, inp_filename, FProvider.SharedFolder, inp_filename)
            Dim in As Intent
            in.Initialize(in.ACTION_VIEW, "")
            FProvider.SetFileUriAsIntentData(in, inp_filename)
            'Type must be set after calling SetFileUriAsIntentData
            in.SetComponent("android/com.android.internal.app.ResolverActivity")
            in.SetType("application/pdf")
            
 
            StartActivity(in)
                    
        End If


part of manifest :
manifest part:
AddManifestText(<uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    android:maxSdkVersion="34" />
)

AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <files-path name="name" path="shared" />
)



It works fine, but only for part of devices . Some part of devices give us error like this:

error description:
android.content.ActivityNotFoundException: Unable to find explicit activity class {android/com.android.internal.app.ResolverActivity}; have you declared this activity in your AndroidManifest.xml, or does your intent not match its declared <intent-filter>?


Is there some stable solution how to open PDF file? . It means for all devices with SDK-25 and higher.



Many thaks for your answer.
 
Top