Android Question [Solved] Starting an Intend fails on Android 8 and above???

opus

Active Member
Licensed User
Longtime User
I'm trying to start an intend to start a "send via.." intend.
This works on an old Android 4.4.2 device, however on devices with Android 8+ it fails.

Notes:
The old device migth be positively affected by the manifest-setting:
Project Manifest:
<uses-permission
  android:name="android.permission.WRITE_EXTERNAL_STORAGE"
  android:maxSdkVersion="19" />
)

The used code:
Send Via Code:
Private Sub SendVia_Click
    'Sendet das aktuelle Spiel
    'zuerst das Spiel speichern
    Dim lSpielstand As String=Spielstand_speichern
    Dim lSerial As Serial
    lSerial.Initialize("mySerial")
    Dim lFileName As String= lSerial.Name & "_Patience.dat"
    Dim lTW As TextWriter
    lTW.Initialize(File.OpenOutput(rp.GetSafeDirDefaultExternal("") , lFileName, False))
    lTW.WriteLine(lSpielstand)
    lTW.Close
    Dim lUri As Uri 'ContentResolver library
    lUri.Parse("file://" & File.Combine(rp.GetSafeDirDefaultExternal(""),lFileName))
    Dim lIntent As Intent
    lIntent.Initialize(lIntent.ACTION_SEND, "file://" & File.combine(rp.GetSafeDirDefaultExternal(""),lFileName))
    lIntent.PutExtra("android.intent.extra.STREAM",lUri)
    lIntent.SetType("text/*")
    Log(File.Exists(rp.GetSafeDirDefaultExternal(""),lFileName))
    StartActivity(lIntent)
End Sub

The log shows "True" just before the "StartActivity(lIntent)" which fails with:

Error:
android.os.FileUriExposedException: file:///storage/emulated/0/Android/data/Opus.Patience/files/Galaxy Tab A_Patience.dat exposed beyond app through ClipData.Item.getUri()

Is there a limitation on such actions?
 

opus

Active Member
Licensed User
Longtime User
I did read this thread, however the relation to Intend was not obvious for me.
Thanks!
 
Upvote 0

opus

Active Member
Licensed User
Longtime User
Did read it again, did changes in the code and now this part works again.
I guess the related part (starting the app by clicking on the recieved file, in other words using a starting intent) has to be adjusted as well.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…