Android Question problems opening email attachment with intent

fastlingo

Member
I get this error in Crashlytics. It happens when a user opens an email attachement with the app. (android 8)

Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/bluetooth/AIRTEL Users.stk (Permission denied)
at java.io.FileInputStream.open0(FileInputStream.java)
at java.io.FileInputStream.open(FileInputStream.java:200)

also this one on another device (android 9)

Fatal Exception: java.io.FileNotFoundException: /storage/emulated/0/Download/VK/emailtransfer.700 (Permission denied)
at java.io.FileInputStream.open0(FileInputStream.java)
 

fastlingo

Member
The thing is, I don't get this error on any of my test devices.

This is the relevant code when the user presses on the email attachment and chooses to open it in my app.

B4X:
Dim Intent1 As Intent
    Intent1 = Activity.GetStartingIntent

    If Intent1.Action = "android.intent.action.VIEW" Then    ' The activity has been called from outside the app
           
    Dim jo As JavaObject
    Dim cd As String = jo.InitializeStatic("anywheresoftware.b4a.objects.streams.File").GetField("ContentDir")
    Dim UriString As String = Intent1.GetData
    Dim Inp As InputStream  = File.OpenInput(cd , UriString)
    Dim Out As OutputStream = File.OpenOutput(File.DirInternal, "emailtransfer.txt", False)


    File.copy2(Inp, Out)
    Inp.Close
    Out.Close


Where in all this should I use file provider? on the line where I get ContentDir?
 
Upvote 0
Top