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

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

where is the code which raises the error?
Code:
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
What is the solution ?
You should use runtime permissions and your code should include something like this:
Code:
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
You should use runtime permissions and your code should include something like this:
Code:
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
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
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
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
Test with
Code:
    If File.Exists(rp.GetSafeDirDefaultExternal(""),"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",rp.GetSafeDirDefaultExternal(""),"fav.db")
   End If
or better yet
Code:
    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
Test with
Code:
    If File.Exists(rp.GetSafeDirDefaultExternal(""),"fav.db") =  False Then
       File.Copy(File.DirAssets,"fav.db",rp.GetSafeDirDefaultExternal(""),"fav.db")
   End If
or better yet
Code:
    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
Code:
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
this code work :
Code:
If File.Exists(rp.GetSafeDirDefaultExternal(""),pdfname) =  False Then
        File.Copy(File.DirAssets,pdfname,rp.GetSafeDirDefaultExternal(""),pdfname)
but last line not work:
Code:
pdf.Initialize("PDFView",File.Combine(File.DirDefaultExternal,pdfname),1,True,True)

How to correct ???
 
Upvote 0
this code work :
but last line not work:
Code:
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.
Back
Top