Hi, all
Before the change of targetSdkVersion to 26 the following code showed an image through an attempt using the default image viewer.
After the change now gives error:
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/app/files/sample.jpg exposed beyond app through Intent.getData()
After reading a couple of posts I changed file combine to cfpURI, but dont open nothing...
What's the right way to do it now?
thx in advance!
Before the change of targetSdkVersion to 26 the following code showed an image through an attempt using the default image viewer.
B4X:
Dim viewINT As Intent
dim img,dr,fn as String
dr = File.DirDefaultExternal
fn = "sample.jpg"
img = "file://" & File.Combine(dr, fn)
viewINT.Initialize(viewINT.ACTION_VIEW,img)
viewINT.SetType("image/*")
Try
StartActivity(viewINT)
Catch
ToastMessageShow("ERROR:" & CRLF & img,True)
End Try
After the change now gives error:
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/app/files/sample.jpg exposed beyond app through Intent.getData()
After reading a couple of posts I changed file combine to cfpURI, but dont open nothing...
B4X:
Dim viewINT As Intent
dim img,dr,fn as String
dr = File.DirDefaultExternal
fn = "sample.jpg"
img = cfpURI(dr, fn)
viewINT.Initialize(viewINT.ACTION_VIEW,img)
viewINT.SetType("image/*")
Try
StartActivity(viewINT)
Catch
ToastMessageShow("ERROR:" & CRLF & img,True)
End Try
Sub cfpURI(Dir As String, FileName As String) As Object
Dim FileProvider As JavaObject
Dim context As JavaObject
context.InitializeContext
FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
Dim f As JavaObject
f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub
What's the right way to do it now?
thx in advance!