Android Question how to create the "share" menu in my app

dexMilano

Active Member
Licensed User
Longtime User
Hallo all,
i want to share information using the "share" menu.
Particularly I need to send this by email or to save in dropbox.
I don't want to integrate this feature in the app, but using the collaboration of the user selecting in the menu of compatible application already installed.

I think
- I need to store info in a file (is it necessary?)
- I need to use the intent (not sure about it)

Unfortunately I cannot understand how to use the intent
I've found a tutorial
and another useful post
but none of them are conclusive to me.

Also guides don't seem focused on this point.

Any clue/comment/code is welcome.

TIA

dex
 

dexMilano

Active Member
Licensed User
Longtime User
Hi thedesolatesoul,

I've a list of records (can be a CSV file, however a TXT file).
I want to save on dropbox and/or send by email.

I've seen these tread but they didn't help me a lot.
The first link to the second
The second cannot share with dropbox and gmail (as described in the messages)

However it is not very clear the mechanism of using intent.
How is the process?

dex
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi thedesolatesoul,

I've a list of records (can be a CSV file, however a TXT file).
I want to save on dropbox and/or send by email.

I've seen these tread but they didn't help me a lot.
The first link to the second
The second cannot share with dropbox and gmail (as described in the messages)

However it is not very clear the mechanism of using intent.
How is the process?

dex


"mechanism of using intent"... b4a or Android?

Android: http://developer.android.com/reference/android/content/Intent.html

B4a: http://www.b4x.com/android/forum/th...app-communication-with-intents.30608/#content
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
I am using the following code for share button:
B4X:
Dim ShareIt As Intent
    ShareIt.Initialize (ShareIt.ACTION_SEND,"")
    ShareIt.SetType ("text/plain")
    ShareIt.PutExtra ("android.intent.extra.TEXT","Download at Google Play: https://play.google.com/store/apps/details?id=YOUR_PACKAGE")
    ShareIt.PutExtra ("android.intent.extra.SUBJECT","YOUR SUBJECT")
    ShareIt.WrapAsIntentChooser("Share Application Via...")
StartActivity (ShareIt)

Of cause it depends of what you want to share but the idea is that.

JAVA code example of sending any file by email as attachement (from Stackoverflow):
B4X:
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new 
            File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));
 
Last edited:
Upvote 0

dexMilano

Active Member
Licensed User
Longtime User
Maybe I'm missing something basic.

@LucaMs
The link you posted are about intent, but maybe it seems not straitghtforward to use it
I read it
I will read it again however.

@Johnmceroy
Your code (very useful) send the text directly.
A question what I've to to do to attach the file (in the above code I added to the text).

However I'm still afraid I'm missing something.
:-(

dex
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Maybe I'm missing something basic.

@LucaMs
The link you posted are about intent, but maybe it seems not straitghtforward to use it
I read it
I will read it again however.

@Johnmceroy
your example (I think) is not what I need to do:
I click on the share button in my app
I have to show the list of possibilities with related icon (dropbox, email, gmail,...) (who manage this list?)
here I choose the one I want
the content is sent to the application (which content and how?)

Your code (very useful) send the text directly to sms application (why this and not another one like email?)
I cannot see any "chooser".

However I'm afraid I'm missing something.
:-(

dex


I have not posted code, but only two links.

Depending on the type of data contained in the intent, is the operating system that shows you a list of apps that can use it.

(below, from: http://developer.android.com/reference/android/content/Intent.html)

Intent Resolution
There are two primary forms of intents you will use.

  • Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.

  • Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.

I have not used them with B4A. That is why I posted this link: http://www.b4x.com/android/fo...app-communication-with-intents.30608/#content
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
This will work for email:
B4X:
Dim Message As Email
    Message.To.Add("[email protected]")
    Message.Subject = "NJ Logs"
    Message.Attachments.Add(File.Combine(File.DirDefaultExternal , "debuglog"))
    StartActivity(Message.GetIntent)

For Dropbox it can be tricky,
something like: (code taken from here: http://www.b4x.com/android/forum/threads/send-an-mms-using-b4a-question.16360/#post-93277)
B4X:
Dim iIntent As Intent 

iIntent.Initialize(iIntent.ACTION_SEND, "")
iIntent.PutExtra("android.intent.extra.STREAM", CreateUri("file://" & File.Combine(File.DirDefaultExternal, "myfile")))
StartActivity(iIntent)

-------------------------------------------

Sub CreateUri(uri AsString) AsObject
 Dim r AsReflector
Return r.RunStaticMethod("android.net.Uri", "parse", ArrayAsObject(uri), ArrayAsString("java.lang.String"))
 End Sub
 
Upvote 0
Top