Android Question File Read Permisson Denied Or File Not Found Exception?

Status
Not open for further replies.

RishiKumar2210

Active Member
Hi All, I am trying to read the text file in the mobile's package name storage Folder(File.DirDefaultExternal), But it shows following Error
B4X:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.sdmmarketing/files/Registration Details/registrationdetails.txt (Permission denied)

When I connect Mobile with B4a with the same wifi connection It Works. But When I open With connecting, It shows an Error
 

sirjo66

Well-Known Member
Licensed User
Longtime User
As Erel already tell to you, you can't use File.DirDefaultExternal
You can use:
B4X:
Dim rp As RuntimePermissions
Dim MyFolder = rp.GetSafeDirDefaultExternal("")
or
B4X:
Dim MyFolder = XUI.DefaultFolder
 
Upvote 0

RishiKumar2210

Active Member
B4X:
Dim lr_runtimepermission As RuntimePermissions
        lr_runtimepermission.GetSafeDirDefaultExternal("")
        
        If(File.Exists(File.DirDefaultExternal & "/Registration Details", "" )) = False Then

            File.MakeDir(File.DirDefaultExternal, "Registration Details")

            File.Copy(File.DirAssets,"registrationdetails.txt",File.DirDefaultExternal & "/Registration Details", "registrationdetails.txt")

            File.WriteString(File.DirDefaultExternal, "/Registration Details/registrationdetails.txt", ls_jsonstr)
        Else
            File.Delete(File.DirDefaultExternal, "/Registration Details/registrationdetails.txt")

            File.MakeDir(File.DirDefaultExternal, "Registration Details")

            File.Copy(File.DirAssets,"registrationdetails.txt",File.DirDefaultExternal & "/Registration Details", "registrationdetails.txt")

            File.WriteString(File.DirDefaultExternal, "/Registration Details/registrationdetails.txt", ls_jsonstr)
        End If
            
        dialog_progress.dismissWithAnimation
        ToastMessageShow("Registered Successfully", True)

This is My Code.
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…