I want to download and open the file that I downloaded, I use the following programming code but the error and don't know where the error is
Error Log
Code:
Sub Class_Globals
Public rp As RuntimePermissions
Public SPMIfolder As String=rp.GetSafeDirDefaultExternal("SPMI")
End Sub
Private Sub DownloadFile(sLink As String,sFileName As String)
Dim j As HttpJob
j.Initialize("", Me)
j.Download(sLink)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim splitta() As String = Regex.Split("\.", sFileName)
Dim estensione As String = splitta(1)
Dim out As OutputStream = File.OpenOutput(SPMIfolder, sFileName, False)
File.Copy2(j.GetInputStream, out)
out.Close '<------ very important
Dim apro As Int
apro = Msgbox2("Do you want Open Document in attachment ?", "Message", "Yes","","No", Null)
If apro = DialogResponse.POSITIVE Then
Dim i As Intent
i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(SPMIfolder, sFileName))
i.SetComponent("android/com.android.internal.app.ResolverActivity")
Select estensione
Case "pdf"
i.SetType("application/pdf")
Log("PDF------")
Case "docx"
i.SetType("application/vnd.openxmlformats-officedocument.wordprocessingml.document")
Case "txt"
i.SetType("text/plain")
Case "jpg"
i.SetType("image/jpg")
Case "jpeg"
i.SetType("image/jpeg")
End Select
StartActivity(i)
End If
Else
ToastMessageShow("Error: " & J.ErrorMessage , True)
End If
j.Release
Error Log
B4X:
Error occurred on line: 259 (DocumentDetail)
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/b4a.example/files/SPMI/1605074220_sample (4).pdf exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:2141)
at android.net.Uri.checkFileUriExposed(Uri.java:2391)
at android.content.Intent.prepareToLeaveProcess(Intent.java:11848)
at android.content.Intent.prepareToLeaveProcess(Intent.java:11797)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1722)
at android.app.Activity.startActivityForResult(Activity.java:5377)
at android.app.Activity.startActivityForResult(Activity.java:5335)
at android.app.Activity.startActivity(Activity.java:5721)
at android.app.Activity.startActivity(Activity.java:5674)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:857)
at b4a.example.documentdetail$ResumableSub_DownloadFile.resume(documentdetail.java:677)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)