Android Question PDF View FileProvider Error

NotRequired

New Member
Hello! I have been trying to open a pdf file in my proyect implementing the FileProvider library, but i always get errors. I tried running an exemplo of FileProvider that i found in another post, and that one worked, but when i try the code in my proyect it simply crash.

Please help me!

App:
Sub Process_Globals
    Dim Socket1 As Socket
    Dim AStreams As AsyncStreams
    Private xui As XUI
    Private tmr As Timer
End Sub

Sub Globals
    Private CircularProgressBar1 As CircularProgressBar
    Private CircularProgressBar2 As CircularProgressBar
    Private CircularProgressBar3 As CircularProgressBar
    Private CircularProgressBar4 As CircularProgressBar
    Private SplashPanel As Panel
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 As Label
    Private BtnTG As ToggleButton
    Private BtnH As Button
    Dim img As BitmapDrawable
    Private newFont As CustomFonts
End Sub


Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("controldeagua")
    Activity.SetBackgroundImage(LoadBitmap(File.DirAssets, "waterBG7.jpg"))
    img.Initialize(LoadBitmap(File.DirAssets, "OFF.png"))
    img.Gravity = Gravity.FILL
    BtnTG.Background = img
    newFont.Initialize("Aiden-v7DO.ttf")
    newFont.SetCustomFontsToAllViews(Activity)
    If FirstTime Then
        ShowSplash
    End If
    Activity.Title="Calidad Del Agua"
    tmr.Initialize("DoSomething", 50)
    tmr.Enabled = True
End Sub

private Sub ShowSplash
    SplashPanel.Visible = True
    BtnTG.Visible = False
    BtnH.Visible = False
    Sleep(1500)
    SplashPanel.SetBackgroundImage(LoadBitmap(File.DirAssets, "universidad-popular-del-cesar-seeklogo.com.png"))
    Sleep(1500)
    SplashPanel.Visible = False
    BtnTG.Visible = True
    BtnH.Visible = True
End Sub

Private Sub DoSomething_Tick

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Socket1_Connected (Successful As Boolean)
    If Successful Then
        AStreams.Initialize(  Socket1.InputStream,     Socket1.OutputStream,   "AStreams")
    End If
End Sub


Sub AStreams_NewData (Buffer() As Byte)
    Dim msg As String
    Dim numbers() As String
    msg = BytesToString( Buffer,  0, Buffer.Length, "CP437")
    numbers = Regex.Split("_", msg)
    If numbers(0) > 14 Then
        CircularProgressBar1.Value = 14
    Else If numbers(0) < 0 Then
        CircularProgressBar1.Value = 0
    Else
        CircularProgressBar1.Value = numbers(0)
    End If
    CircularProgressBar1.Range = 14
    CircularProgressBar1.ValueUnit = " pH"
    If numbers(1) > 100 Then
        CircularProgressBar2.Value = 100
    Else If numbers(1) < 0 Then
        CircularProgressBar2.Value = 0
    Else
        CircularProgressBar2.Value = numbers(1)
    End If
    CircularProgressBar2.Range = 100
    CircularProgressBar2.ValueUnit = " °C"
    If numbers(2) > 2000 Then
        CircularProgressBar3.Value = 2000
    Else If numbers(2) < 0 Then
        CircularProgressBar3.Value = 0
    Else
        CircularProgressBar3.Value = numbers(2)
    End If
    CircularProgressBar3.Range = 2000
    CircularProgressBar3.ValueUnit = " ppm"
    If numbers(3) > 4000 Then
        CircularProgressBar4.Value = 4000
    Else If numbers(3) < 0 Then
        CircularProgressBar4.Value = 0
    Else
        CircularProgressBar4.Value = numbers(3)
    End If
    CircularProgressBar4.Range = 4000
    CircularProgressBar4.ValueUnit = " uS/cm"
End Sub

Sub AStreams_Error

End Sub

Private Sub BtnTG_CheckedChange(Checked As Boolean)
    If Checked = True Then
        img.Initialize(LoadBitmap(File.DirAssets, "ON.png"))
        Try
            If Socket1.IsInitialized = False Then
                Socket1.Initialize( "Socket1")
            Else
                Socket1.Close
                Socket1.Initialize("Socket1")
            End If
            Socket1.Connect( "192.168.4.1",  8080,   0)
        Catch
            Log(LastException)
        End Try
    Else
        img.Initialize(LoadBitmap(File.DirAssets, "OFF.png"))
        Socket1.Close
    End If
    img.Gravity = Gravity.FILL
    BtnTG.Background = img
End Sub


Private Sub BtnH_Click
    Dim FileName As String = "manualapp.pdf"
    File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
    Dim in As Intent
    in.Initialize(in.ACTION_VIEW, "")
    Starter.Provider.SetFileUriAsIntentData(in, FileName)
    'Type must be set after calling SetFileUriAsIntentData
    in.SetComponent("android/com.android.internal.app.ResolverActivity")
    in.SetType("application/pdf")
    StartActivity(in)
End Sub

Log Error:
Registro conectado a:  Xiaomi Redmi Note 8
--------- beginning of main
*** Service (starter) Create ***
Using FileProvider? true
** Service (starter) Start **
** Activity (main) Create (first time) **
** Activity (main) Resume **
main_btnh_click (java line: 493)
java.io.FileNotFoundException: manualapp.png
    at android.content.res.AssetManager.nativeOpenAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:910)
    at android.content.res.AssetManager.open(AssetManager.java:887)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:208)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:341)
    at b4a.example.main._btnh_click(main.java:493)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7507)
    at android.view.View.performClickInternal(View.java:7484)
    at android.view.View.access$3600(View.java:839)
    at android.view.View$PerformClick.run(View.java:28689)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:8037)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
--------- beginning of crash
 
Last edited:
Top