Android Question File access error

Levisvv

Member
Licensed User
Longtime User
I am trying to include some pdf files in the /Files/ assets folder with my app then open them from my app.
So I discovered that I cannot have an external pdf viewer load a file from file.DirAssets, so I am trying to copy the files first.

I saved a file: "My_Test_PDF_File.pdf" to my /files/ folder, but I cannot see if when using this code. what on earth could I be doing wrong?

B4X:
Dim FLname As String
    FLname = "My_Test_PDF_File.pdf"
    FLname=FLname.ToLowerCase
    If File.Exists(File.DirAssets,FLname) Then
        ToastMessageShow("Found",True)
    Else
        ToastMessageShow("NOT Found: " & FLname,True)
    End If
    File.Copy(File.DirAssets,FLname,File.DirInternalCache,FLname)

I always get a NOT Found error???
 

Levisvv

Member
Licensed User
Longtime User
In my experience, reading from the dirassets folder never seems to work when uppercase is used.
Now I just noticed that my file IS indeed seen, but only if it has no uppercase characters at all.
What is up with that???
 
Upvote 0

Levisvv

Member
Licensed User
Longtime User
Ok now I have a pdf file available but why do I always get an error "document cannot be opened" with the following code:

B4X:
Sub PDF1_Click
    Dim Intent1 As Intent
    If File.Exists(File.DirInternalCache,"dcs.pdf") = True Then
        Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(File.DirInternalCache, "dcs.pdf"))
        Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
        Intent1.SetType("application/pdf")
        Intent1.WrapAsIntentChooser ("Choose Viewer")
        StartActivity(Intent1)
    End If
End Sub

I confirmed that the file is indeed there.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I am trying to include some pdf files in the /Files/ assets folder with my app then open them from my app.
So I discovered that I cannot have an external pdf viewer load a file from file.DirAssets, so I am trying to copy the files first.

I saved a file: "My_Test_PDF_File.pdf" to my /files/ folder, but I cannot see if when using this code. what on earth could I be doing wrong?

B4X:
Dim FLname As String
    FLname = "My_Test_PDF_File.pdf"
    FLname=FLname.ToLowerCase
    If File.Exists(File.DirAssets,FLname) Then
        ToastMessageShow("Found",True)
    Else
        ToastMessageShow("NOT Found: " & FLname,True)
    End If
    File.Copy(File.DirAssets,FLname,File.DirInternalCache,FLname)

I always get a NOT Found error???


You should add the pdf file using the IDE Tab "File"
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Ok now I have a pdf file available but why do I always get an error "document cannot be opened" with the following code:

B4X:
Sub PDF1_Click
    Dim Intent1 As Intent
    If File.Exists(File.DirInternalCache,"dcs.pdf") = True Then
        Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(File.DirInternalCache, "dcs.pdf"))
        Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
        Intent1.SetType("application/pdf")
        Intent1.WrapAsIntentChooser ("Choose Viewer")
        StartActivity(Intent1)
    End If
End Sub

I confirmed that the file is indeed there.


I would try to use other pdf files, perhaps the file format is not correct
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
B4X:
Sub OpenPDF(Dir As String, FileName As String)
    Dim aIntent As Intent
    Try
        aIntent.Initialize(aIntent.ACTION_VIEW, "file://" & File.Combine(Dir, FileName))
        aIntent.SetType("application/pdf")
        StartActivity(aIntent)
    Catch
        Msgbox(LastException.Message, "")
    End Try
End Sub

Sub OpenPDF2(Dir As String, FileName As String)
    Dim Intent1 As Intent
    If File.Exists(Dir,FileName) = True Then
        Intent1.Initialize(Intent1.ACTION_VIEW, "file://" & File.Combine(Dir, FileName))
        Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
        Intent1.SetType("application/pdf")
        Intent1.WrapAsIntentChooser ("Choose Viewer")
        StartActivity(Intent1)
    End If
End Sub
 
Upvote 0
Top