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
DirAssets is readonly. You can not write here.

where is the code which raises the error?
B4X:
pdfname = "vb2010.pdf"
    File.Copy(File.DirAssets,pdfname,File.DirDefaultExternal,pdfname)
    pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,pdfname),1,True,True)

whan i start the app can't read the files from DirAssets
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What is the solution ?
You should use runtime permissions and your code should include something like this:
B4X:
Dim rp As RuntimePermissions   'need runtime permissions library. This line should preferably in Starter service
    File.Copy(File.DirAssets,pdfname,rp.GetSafeDirDefaultExternal(""),pdfname)
Also: Your target SDK in your manifest should be: 26 not 28

Maybe you have used capital letters in your actual file name?
It does not matter anymore. The file names are internally converted to lower case. So, it is not a problem if the asset files are in uppercase.
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
You should use runtime permissions and your code should include something like this:
B4X:
Dim rp As RuntimePermissions   'need runtime permissions library. This line should preferably in Starter service
    File.Copy(File.DirAssets,pdfname,rp.GetSafeDirDefaultExternal(""),pdfname)
Also: Your target SDK in your manifest should be: 26 not 28


It does not matter anymore. The file names are internally converted to lower case. So, it is not a problem if the asset files are in uppercase.
I will test this

Thanks for replay . I will test this code
can you give me this Library :runtime permissions library ?
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
I did not know to do that

if this file in DirAssets : index.txt
how to access it ?

please write to me the full code
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
I did not know to do that

if this file in DirAssets : index.txt
how to access it ?

please write to me the full code

The runtime permissions tutorial (https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content) provides all the information you need to be able to write the code yourself. If there are other things that aren't clear to you, then search the forum for the specific issue you are having & if you still can't figure it out then ask - but don't expect other forum members to write the code for you. You won't learn anything if you just copy & past code that others have written.

- Colin.
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
The runtime permissions tutorial (https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/#content) provides all the information you need to be able to write the code yourself. If there are other things that aren't clear to you, then search the forum for the specific issue you are having & if you still can't figure it out then ask - but don't expect other forum members to write the code for you. You won't learn anything if you just copy & past code that others have written.

- Colin.

Thanks a lot

I did not find link of library download
 
Upvote 0

IdasI4A

Active Member
Licensed User
Longtime User
Test with
B4X:
    If File.Exists(rp.GetSafeDirDefaultExternal(""),"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",rp.GetSafeDirDefaultExternal(""),"fav.db")
   End If
or better yet
B4X:
    dim Carpeta as String

    Carpeta=rp.GetSafeDirDefaultExternal("")
    If File.Exists(Carpeta,"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",Carpeta,"fav.db")
   End If
 
Upvote 0

Alansari

Member
Licensed User
Longtime User
Test with
B4X:
    If File.Exists(rp.GetSafeDirDefaultExternal(""),"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",rp.GetSafeDirDefaultExternal(""),"fav.db")
   End If
or better yet
B4X:
    dim Carpeta as String

    Carpeta=rp.GetSafeDirDefaultExternal("")
    If File.Exists(Carpeta,"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",Carpeta,"fav.db")
   End If
Waw Thats work

Thanks a lot ms.ldasl4A

look at this code .. not work
please edit it
B4X:
File.Copy(File.DirAssets,aaa.pdf,File.DirDefaultExternal,aaa.pdf)
    pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,aaa.pdf),1,True,True)
 
Last edited:
Upvote 0

Alansari

Member
Licensed User
Longtime User
this code work :
B4X:
If File.Exists(rp.GetSafeDirDefaultExternal(""),pdfname) =  False Then
        File.Copy(File.DirAssets,pdfname,rp.GetSafeDirDefaultExternal(""),pdfname)
but last line not work:
B4X:
pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,pdfname),1,True,True)

How to correct ???
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
this code work :
but last line not work:
B4X:
pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,pdfname),1,True,True)

How to correct ???

What is pdf? Post your declaration for the pdf object.

- Colin.
 
Upvote 0
Status
Not open for further replies.
Top