Android Question Sharing a string over some social media

udg

Expert
Licensed User
Longtime User
Hi all,
I have a B4XFloatTextField which contains a long string that I would like to post on a few social media (Telegram, Signal, Whatsapp).
One way is the copy&paste technique using the clipboard (I already did that).
Another could be the sharing mechanism through intents for those app that expose themselves as sharing targets.
I'm aware of a nice lib by @hatzisn but it seems that at this moment it lacks Telegram and Signal.

Any other hassle free way?

TIA
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
TOKEN="YOUR_TOKEN"
ID="YOUR_ID"
URL="https://api.telegram.org/bot$TOKEN/sendMessage"

curl -s -X POST $URL -d chat_id=$ID -d text="Hello World"

you need to have an bot created using botfather and have its token.
also you need the id of the chat.

I found above code using google.
Reference

Edit: Also found this. It can send to Signal, Telegram, Whatsapp
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Longtime User
Thanks Manfred.
The app is not for me (this time) and moreover I don't use any social myself, so it's kind of shooting in the dark.
From your reply I see that the user needs to activate a bot in his channel in order to give me the token. Same for the chat's ID.

As an alternative, can I make my app display a list of possible sharing targets, letting the user to choose app, channel and whatever else could be needed?

What do you think? Could it be more general and easir for someone not necessarily able to start a bot or making any special configuration to his account?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
As an alternative, can I make my app display a list of possible sharing targets, letting the user to choose app, channel and whatever else could be needed?
I don´t see how this could work with Whatsapp as there is no open Api for this.
Even not Signal as there is no Api for that,
Even not Telegram as there is no Api for that. As i only have knowledge about Telegram i only can answer here. To send a Message to Telegram one need to know the ChatID (Room or user-id to send to). Same for Signal.

Your request more sounds: It´s like the user want to freely configure how to send spam to anywhere.

My thought: good that this is not possible. ;-)

PD: A Telegram Bot will not help here AT ALL! The destination-user must start the Chat with your Bot ONCE to allow him so send anything. You can not initialy send a message to any unknown member in Telegram if it is a bot. Bots in Telegram needs to get authentificated by sending them an initial message to start a conversation with the bot. Only then the bot can send a Message to this User.
A Bot can not send anything to anywhere if he does not get a Initial Chat from "anywhere".

At least this is like this in Telegram (if i remember correctly!).
 
Last edited:
Upvote 0

udg

Expert
Licensed User
Longtime User
Your request more sounds: It´s like the user want to freely configure how to send spam to anywhere.
I can understand your concern, but no, I'm not going to help any spammer or criminal.
On the contrary, my goal is to try to help someone whose freedom of speech is at risk.
So my app is a simple message encryption system. Once my user has his message encrypted, it could be published on any channel (Whatsapp, mail, Telegram..) he likes knowing that only those who know the current password could decrypt it.
On my first draft I used the clipboard to copy and paste the message from my app to the "social" medium and viceversa (in order to decrypt).

Having a way to select which sharing channel to use among those available on the device could be nice. I guess that my app should be configured as a sharing target (for text) too in order to keep the two-way message exchange. So when in Whatsapp (and similar) the user click on the encrypted message, than the button Share with and select my app.

Nothing too different from copy&paste, just simpler and more modern, I think.

udg
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Just a quick update.
I found another way to send the encrypted message to Telegram/Whatsapp.. using a simple intent
B4X:
Private Sub SendMsg(tmsg As String)
    Dim i As Intent
    i.Initialize(i.ACTION_SEND, "")
    i.SetType("text/plain")
    i.PutExtra("android.intent.extra.TEXT", tmsg)
    i.WrapAsIntentChooser("Choose an app")
    StartActivity(i)
End Sub

Unfortunatley, picking a message in WA, Telegram and presumably any other social media in order to launch a "Share with" command to send it to my app seems to be an unavailable option. So the user receiving an encrypted message on its favourite social has to copy it to the clipboard and then paste it in my app to decrypt it.
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
This is a different request. If you want to receive text or images from other apps into your own, you must set your app as a sharing target. Take a look at this, especially the mime type

 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I don't use Whats app or Telegram, so are you saying that neither of those apps can "Share to" an email program?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I couldn't find the option "Share with" once I selected an existing message. Tried both WA and Telegram.
you must set your app as a sharing target.
I did something like that, but the problem seems that those social apps can't share a text message with an external app. They do have a forward option, but it seems limited to other "channels" of the same app.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…