Jump to content
schaumermal

App as target via "share"

Recommended Posts

Hello,

 

i have the following question:

 

Can an app based on Delphi serve as a target on the mobile when sharing images or documents, for example?
When I use the option "Share", (e.g. in the galary) my app doesn't appear as a target.

1. Is this even possible?

2. If "yes", is there an example of what needs to be done so that the app can receive data?

 

thx

Share this post


Link to post

first read this: https://developer.android.com/training/sharing/receive

 

This demo shows interaction between Android applications using intents. It consists of two applications, SendIntent that creates and send the intent, and ReceiveIntent that receives the intent and displays the information.

https://docwiki.embarcadero.com/CodeExamples/Sydney/en/FMX.Android_Intents_Sample

Edited by programmerdelphi2k

Share this post


Link to post

Thank you for this hint.


I tested it and "hopefully" understood the principle.
However, I can't get my app to be displayed as a target if I want to share a photo in the gallery or the document folder on my mobile.

 

I added the following section in the AndroidManifest.template.xml:

 

<intent filter>
                 <action android:name="android.intent.action.VIEW" />
                 <category android:name="android.intent.category.DEFAULT" />
                 <category android:name="android.intent.category.BROWSABLE" />
                 <data android:mimeType="image/*" />

</intent-filter>

 

I thought the entry above controls that my app can receive this type of data but it is not displayed as a target 😞

 

Share this post


Link to post

hi @schaumermal

I think that the problem here is the "MIME" used to find the apps on Android!

really the sample by Embarcadero DONT WORKS for me too!

 

then, I have tested in Embarcadero DEMO project with generic "MIME" =  */* and it works! You app will be showed on "choicer"!

 

test in your project:  

  • SENDER app:  use this:    Intent.setType(StringToJString('*/*')); //text/pas
  • RECEIVER app: use this on Android manifest:   <data android:mimeType="*/*" />        -->  //text/pas--> on intent-filter....

now, all apps that accept your send will be showed on "choicer"

 

https://developer.android.com/reference/androidx/media3/common/MimeTypes

https://android.googlesource.com/platform/external/mime-support/+/9817b71a54a2ee8b691c1dfa937c0f9b16b3473c/mime.types

Share this post


Link to post

hi @programmerdelphi2k

 

thanks for your previous help.

 

Maybe I didn't express myself correctly.
I don't want to send files, i only want to receive files.

 

For example, if I select a file in the gallery or downloads folder and click share, I want my app to appear as a possible destination as well.

I see Gmail, Bluetooth, Music, WhatsApp, etc. as possible targets but not my app.

Unfortunately, despite your change, my app doesn't show up as a possible destination when I try to share a file from the gallery or from a folder.

 

 

 

Share this post


Link to post

look, your app "just" will be showed if "it" is "identifyed" in your "Android manifest" with the same "MIME" that "other" apps exporting data/info/etc...

the Embarcadero sample, works here (but just using MIME = "*/*") --> this a sample!!! not a final app for real-usage!   IF YOU DONT WANT  a sender-app.. .ok, pay attention only in RECEIVER app!

 

if you app desire receive a file (in a universe of files...), it needs be prepared for this... you needs use "Android manifest" for that, indicating the "MIME" used in "other apps"!

for this, you needs knows what is the MIME used by other app!

 

Normally, the "apps" use the MIME known by all ---> see on Android site as above! In rare cases, a MIME (non-default) would can be used... but dont wait for a "blue sky here"

 

Think about this: YOU expect a "cat"!!! SOMEONE send to you a "dog"!!!  what do you do?  --> accept a "dog" and expect a "MEAWWW" or a "AWW AWW" ?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×