Android Question Share pdf or else

yolancomonoro

New Member
hello to all
I use this code to open or share a pdf files but it dos not work at all. Please help me!

this is my code

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("MainKey")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



'713-042124-001
Sub OpenPdf_Click
    Dim i As Intent 'Requires a reference to the Phone library
    Msgbox("file:/" &  File.DirDefaultExternal & "/Hokm.pdf","")
    File.Copy(File.DirAssets,"Hokm.pdf",File.DirDefaultExternal,"Hokm.pdf")
    Msgbox(File.Exists(File.DirDefaultExternal,"Hokm.pdf"),"Hokm.pdf")
    i.Initialize(i.ACTION_VIEW, "file://" &  File.DirDefaultExternal & "/Hokm.pdf")
    i.SetType("application/pdf")
    'i.SetComponent("android/com.android.internal.app.ResolverActivity")
    i.WrapAsIntentChooser("Choose PDF Viewer")
    Try
        StartActivity(i)
    Catch
        ToastMessageShow("oh!! Nooooo",False)
    End Try
   
End Sub


and this is my manifest

[CODE=b4x]'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)

AddPermission(android.PERMISSION_WRITE_EXTERNAL_STORAGE)
AddPermission(android.PERMISSION_READ_EXTERNAL_STORAGE)


'End of default text.


thanks!!
 

yolancomonoro

New Member
when i add an "s" to then "file" on the line 49 code like this

i.Initialize(i.ACTION_VIEW, "files://" & File.DirDefaultExternal & "/Hokm.pdf")

the app was open the below picture but not any programm wil be showed

i have two app for opening pdf file

Open Pdf.jpg
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
- File.DirDefaultExternal is no longer accessable.
- file:// uris are not allowed any longer.
- You need to use FileProvider

 
  • Like
Reactions: zed
Upvote 1

zed

Active Member
Licensed User
follow this example
 
Upvote 0
Top