Android Question Can't read or write from DirAssets

Status
Not open for further replies.

Alansari

Member
Licensed User
Longtime User
Hi Freinds

After i updated SDK to platform 28 the App can't access DirAssets files

B4X:
pdfname = "vb2010.pdf"
    File.Copy(File.DirAssets,pdfname,File.DirDefaultExternal,pdfname)
    pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,pdfname),1,True,True)

What is the solution ?

look the images if there any problems

error0.png
error1.png
error2.png
error4.png
 

Alansari

Member
Licensed User
Longtime User
What is pdf? Post your declaration for the pdf object.

- Colin.
Pdf is library ( PDFView ) for read pdf file

B4X:
Dim pdf As pdfView

pdfname = "vb2010.pdf"
   
    If File.Exists(rp.GetSafeDirDefaultExternal(""),pdfname) =  False Then
        File.Copy(File.DirAssets,pdfname,rp.GetSafeDirDefaultExternal(""),pdfname)
        pdf.Initialize("PDFView",File.Combine(File.DirRootExternal,pdfname),1,True,True)
    End If
last line appear pdf page . but not apear
 
Last edited:
Upvote 0

Alansari

Member
Licensed User
Longtime User
B4X:
File.DirRootExternal
must be the below:
B4X:
rp.GetSafeDirDefaultExternal("")
Code must be consistent.

B4X:
pdf.Initialize("PDFView",File.Combine(rp.GetSafeDirDefaultExternal(""),pdfname),1,True,True)
Thanks but not work . not apear pdf page

Tell me full line of code
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
B4X:
pdf.Initialize("PDFView",File.Combine(rp.GetSafeDirDefaultExternal(""),pdfname),1,True,True)
Thanks but not work . not apear pdf page

Tell me full line of code
Log File.Combine(rp.GetSafeDirDefaultExternal(""),pdfname) & post the result here.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
can you explain more ???
Honestly - you've been a member of this forum since 2014. You should have some idea on how to troubleshoot issues with your code. Add this line of code above your pdf.Initialize statement:

B4X:
Log($"File Combine: ${File.Combine(rp.GetSafeDirDefaultExternal(""),pdfname)}"$)

Run the code, then look in the Log tab (on the right hand side of the B4A IDE) & copy the line that starts with "File Combine:" & paste it into this thread.

- Colin.
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
A couple of thoughts on this:

1) File.Copy probably isn't a blocking method, therefore if you call pdf.Initialize immediately after File.Copy, the file might not yet be available. You should wait until you know that the file has been copied, but I'm not sure if Sleep(0) will work, so you could use an arbitrary sleep time - say 1 second. You could use a Do While Loop to pause execution until the file is copied, but my concern there is that if the file doesn't get copied you'll send up stuck in the loop (unless you also put a timeout in it).
2) You shouldn't repeatedly call rp.GetSafeDirDefaultExternal. If you are only using it in that one sub, then you should assign the first call to a local variable, then use that. If you're using it in other places, then create a global variable in your Starter service & assign it to that:

B4X:
Private pdf As pdfView
Private safeDir as String = rp.GetSafeDirDefaultExternal("")

pdfname = "vb2010.pdf"
   
    If Not(File.Exists(safeDir, pdfname)) Then
        File.Copy(File.DirAssets, pdfname, safeDir, pdfname)
        Sleep(1000)
        If File.Exists(safeDir, pdfname) Then 
            pdf.Initialize("PDFView",File.Combine(safeDir, pdfname),1,True,True)
        Else
            Log("File Not Copied!")
        End If
    End If

- Colin.
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
Honestly - you've been a member of this forum since 2014. You should have some idea on how to troubleshoot issues with your code. Add this line of code above your pdf.Initialize statement:

B4X:
Log($"File Combine: ${File.Combine(rp.GetSafeDirDefaultExternal(""),pdfname)}"$)

Run the code, then look in the Log tab (on the right hand side of the B4A IDE) & copy the line that starts with "File Combine:" & paste it into this thread.

- Colin.
no apear any information about log line

This code to apear the pdf page . so mybe not need Permissions . alraedy pdf file in dir of phone
but need to access pdf file in the phone dir . mybe need to change DirDefaultExternal to other word
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
o apear any information about log line
This thread should not take these many posts ( 28 posts) to solve. Your best bet is to export the project. I am sure someone in the forum will be able to figure it out. The community is always eager to help its members. Here is what you do:
1. In the IDE open your project, then click 'File'
2. Choose 'Export as zip'. Save the file under any given name and attach it to your post.
3. To make it easier for you and everyone else, perhaps you should use Google Translate to translate your post from Arabic to English, if that is possible.
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
This thread should not take these many posts ( 28 posts) to solve. Your best bet is to export the project. I am sure someone in the forum will be able to figure it out. The community is always eager to help its members. Here is what you do:
1. In the IDE open your project, then click 'File'
2. Choose 'Export as zip'. Save the file under any given name and attach it to your post.
3. To make it easier for you and everyone else, perhaps you should use Google Translate to translate your post from Arabic to English, if that is possible.
Ok.Thanks
 
Upvote 0
Status
Not open for further replies.
Top