Android Question Sharing and receiving files from my app with File Provider - problem uri always null

DonManfred

Expert
Licensed User
Longtime User
The problem is that the intent does not contain a STREAM but a contenturi

Change the Activity_resume In the ReceiverApp to

B4X:
Sub Activity_Resume
 
    If IsRelevantIntent(Activity.GetStartingIntent) Then
        Dim starting As Intent = Activity.GetStartingIntent
        'Log(starting)
        'Log(starting.Action)
        If starting.GetData.StartsWith("content") Then
            Dim uri As String = starting.GetData
            Try
                Log("Loading bitmap from ContentUri: " & uri)
                Dim bmp As Bitmap = LoadBitmapSample("ContentDir", uri, 100%x, 100%y)
                Activity.SetBackgroundImage(bmp)
            Catch
                Log(LastException)
            End Try
        Else
            Dim in As JavaObject = Activity.GetStartingIntent
            Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
            Try
                Log("Loading bitmap from: " & uri)
                Dim bmp As Bitmap = LoadBitmapSample("ContentDir", uri, 100%x, 100%y)
                Activity.SetBackgroundImage(bmp)
            Catch
                Log(LastException)
            End Try
        End If

    End If
End Sub

Additionally i changed the targetsdk for both to 26 to force using the fileprovider.

I also added Runtimepermission and this code to the manifest
B4X:
'End of default text.
AddApplicationText(
  <provider
  android:name="android.support.v4.content.FileProvider"
  android:authorities="$PACKAGE$.provider"
  android:exported="false"
  android:grantUriPermissions="true">
  <meta-data
  android:name="android.support.FILE_PROVIDER_PATHS"
  android:resource="@xml/provider_paths"/>
  </provider>
)
CreateResource(xml, provider_paths,
   <external-files-path name="name" path="shared" />
)

WhatsApp Image 2018-01-06 at 09.53.13.jpeg
 

Attachments

  • sharedimagenew.zip
    7.5 KB · Views: 343
Last edited:
Upvote 0
Top