Android Question Share Image between two apps

Blueforcer

Well-Known Member
Licensed User
Longtime User
This Question is a bit special:

I have App 1 wich can get all permissions i need. In this app i choose a image for its own background via ContentChooser.
At some point i will start App 2 via intent, and this app should show the same background image.

Note: App 2 should not display any Runtime Permissions requests!

I tried several things:
- Send the whole bitmap as Intent extra -> filesize to large
- Copy image to ExternalRoot -> App2 cannot access it
- send resolved uri to App2 -> doesnt work either

Is there any other change for App2 to display the same image choosed by App1?
Maybe there is a folder where app1 can copy the image to and app2 can read the image without permission?
 
Last edited:

Blueforcer

Well-Known Member
Licensed User
Longtime User
Post the code and the error message.


B4X:
Dim b As Bitmap = xui.LoadBitmap(File.DirAssets,"logo.png")
    Try
        Dim i As Intent
        Dim pm As PackageManager
        Dim app As App= Main.FrontendApps.Values.Get(actualApp)
        i = pm.GetApplicationIntent(app.packagename)
        i.PutExtra("background",b)
        i.SetComponent(app.packageName & "/.main")
        StartActivity(i)
    Catch
        Log(LastException)
    End Try

(TransactionTooLargeException) android.os.TransactionTooLargeException: data parcel size 2921888 bytes

Accroding to TransactionTooLargeException | Android Developers the filesize is limited to 1MB
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Ok i tried to add the FileProvider Class:

App 1:

B4X:
Dim intent As Intent
Dim pm As PackageManager
intent = pm.GetApplicationIntent(app.packagename)
intent.SetComponent(app.packageName & "/.settings")
          
Dim FileName As String = "logo.png"
File.Copy(File.DirAssets, FileName, Starter.Provider.SharedFolder, FileName)
Starter.Provider.SetFileUriAsIntentData(intent, FileName)
'Type must be set after calling SetFileUriAsIntentData
intent.SetType("image/*")
StartActivity(intent)

App 2:

B4X:
Dim in As JavaObject = Activity.GetStartingIntent
Dim uri As String = in.RunMethod("getParcelableExtra", Array("android.intent.extra.STREAM"))
Dim bmp As Bitmap = LoadBitmapSample("ContentDir", uri, Activity.Width, Activity.Height)
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

Manifest App2:

B4X:
AddActivityText(Settings,
<intent-filter>
   <action android:name="android.intent.action.SEND" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="image/*" />
</intent-filter>)


But getting this error in App 2

B4X:
java.io.FileNotFoundException: No content provider: null
    at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1971)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1800)
    at android.content.ContentResolver.openInputStream(ContentResolver.java:1477)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:212)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.initializeSampleImpl(CanvasWrapper.java:601)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeSample(CanvasWrapper.java:598)
    at anywheresoftware.b4a.keywords.Common.LoadBitmapSample(Common.java:1355)
    at com.awtrix.bockninja.awtrixclass._dotransition(awtrixclass.java:672)
    at com.awtrix.bockninja.settings._activity_resume(settings.java:376)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at com.awtrix.bockninja.settings.afterFirstLayout(settings.java:111)
    at com.awtrix.bockninja.settings.access$000(settings.java:17)
    at com.awtrix.bockninja.settings$WaitForLayout.run(settings.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7701)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I already had this in my manifest. ( I assume this must be in App 1?)
Do i need any special things apart from my posted ones in App 2 wich should receive that image?
 
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
I tried now to use your FileProvider Class example together with my app 2.
Same message
(FileNotFoundException) java.io.FileNotFoundException: No content provider: null
while uri string from getParcelableExtra method is NULL

I used this example for App 2:
Receiving shared images from other apps | B4X Programming Forum
But i had to change the manifest from action.SEND to action.VIEW in order to avoid a crash in the FileProvider example
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://b4a.example.provider/name/b4a.png typ=image/* flg=0x20001 }
 
Last edited:
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Well, i got it.

i changed the reciever code to

B4X:
Dim uri As String = intent.GetData
Dim bmp As Bitmap = LoadBitmapSample("ContentDir", uri, MyActivity.Width, MyActivity.Height)

now its working.
 
Last edited:
Upvote 0
Top