Please help iam stilling getting this error despite the fact that i have allowed the device to access the storage please help
here is my code
here is my code
B4X:
Sub DownloadAndSaveFileP2 (Link As String)
Dim FilePath2 As String = File.Combine(File.DirRootExternal, "Download")
Dim FileName As String = "P2WORK.PDF"
File.Delete(FilePath2, FileName)
Dim Phone As Phone
If Phone.SdkVersion <= 18 Then
Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & FilePath2)
Dim p As Phone
p.SendBroadcastIntent(i)
Else
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim MediaScannerConnection As JavaObject
MediaScannerConnection.InitializeStatic("android.media.MediaScannerConnection")
Dim interface As Object = MediaScannerConnection.CreateEventFromUI("android.media.MediaScannerConnection.OnScanCompletedListener", "ScanCompleted", _
Null)
MediaScannerConnection.RunMethod("scanFile", Array(ctxt, Array As String(FilePath2), Array As String("image/pdf"), interface))
End If
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Link)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "P2WORK.PDF", False)
File.Copy2(j.GetInputStream, out)
out.Close
Dim rp As RuntimePermissions
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
File.Copy(File.DirInternal, "P2WORK.PDF", File.DirRootExternal, "Download/P2WORK.PDF")
Dim FilePath As String = File.Combine(File.DirRootExternal, "Download/P2WORK.PDF")
Dim Phone As Phone
If Phone.SdkVersion <= 18 Then ' min - 4.3.1
Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", "file://" & FilePath)
Phone.SendBroadcastIntent(i)
Else
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim MediaScannerConnection As JavaObject
MediaScannerConnection.InitializeStatic("android.media.MediaScannerConnection")
Dim interface As Object = MediaScannerConnection.CreateEventFromUI("android.media.MediaScannerConnection.OnScanCompletedListener", "ScanCompleted", _
Null)
MediaScannerConnection.RunMethod("scanFile", Array(ctxt, Array As String(FilePath), Array As String("image/pdf"), interface))
End If
End If
End If
j.Release
MsgboxAsync("The downloaded work has been placed in Downloads of Adobe acrobat reader. Please Install adobe acrobat reader incase it is not yet installed on your phone thank you. And Check in Adobe click files. ","Homework Downloaded")
'Sleep(0)'saveimag
ProgressDialogHide
End Sub