Android Question open pdf from dirRootExternal

bernardR

Member
Licensed User
Longtime User
Hello,
I have an app no-google for Android 10 with permission WRITE_EXTERNAL_STORAGE.

I have read:
and I have modified the manifest for fileProvider

I need open the file test.pdf in DirRootExternal.
It not works.

The intent is displayed but not the file (no error'message)

Can you aid me, please ?
 

Mahares

Expert
Licensed User
Longtime User
need open the file test.pdf in DirRootExternal.
You can use the temporary legacy since you are using SDK 29 (OS 10) . Add to manifest:
B4X:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
See this link for more information
 
Upvote 0

bernardR

Member
Licensed User
Longtime User
Here my manifest:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
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" />
)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

I know how get permission WRITE_EXTERNAL_STORAGE by RuntimePermissions.
In manifest, requestLegacyExternalStorage is true,but the intent is displayed but not the file.
Is it possible to program the intent and File Provider for open test.pdf in DirRootExternal ?
Thanks
 
Last edited:
Upvote 0

bernardR

Member
Licensed User
Longtime User
This sub works
B4X:
Sub displayPDF(FileName As String)
    File.Copy(File.DirRootExternal,FileName, Provider.SharedFolder, FileName)
    Dim sp As Intent
    sp.Initialize(sp.ACTION_VIEW, "")
    Provider.SetFileUriAsIntentData(sp, FileName)
    'Type must be set after calling SetFileUriAsIntentData
    sp.SetType("application/pdf")
    StartActivity(sp)
End Sub
I don't know if it works on android 11
 
Upvote 0
Top