Android send message through telegram? - android

I have installed the telegram app and just want to send a message (string) from my app through telegram to a contact.
All I found yet is in the question: How to send a Intent with telegram
with the code:
//Sending message
void intentMessageTelegram(String msg)
{
final String appName = "org.telegram.messenger";
final boolean isAppInstalled = isAppAvailable(this.getApplicationContext(), appName);
if (isAppInstalled)
{
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage(appName);
myIntent.putExtra(Intent.EXTRA_TEXT, msg);//
this.startActivity(Intent.createChooser(myIntent, "Kevin"));
}
else
{
Toast.makeText(this, "Telegram not Installed", Toast.LENGTH_SHORT).show();
}
}
when I use that the telegram opens a contact list. But choosing multiple contacts, It is not sending it to them. If I click on one of them the message will be sent.
How can I send a message without displaying the telegram?
Is there a way to read messages too?
Thanks in advance^^

Related

Couldn't send SMS from Activity , says "could not start conversation"

This code was working, it opens the default SMS app and message appears in textbox , ready to enter number and send, But now this code doesn't work from Above marshmallow.
but now It does not work if the default app is Messaging
Uri uri = Uri.parse("smsto:" + mphoneno);
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", message);
mActivity.startActivity(it);
try below method to open default messaging app
public void sendSMS() {
String number = "12346556"; // The number on which you want to send SMS
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
}

send whatsapp messages to someone not on contact list from android app

I'm developing an application that can send message through whatsapp. I have implemented it by following this answer but it only works for contacts that on my contact list. It keeps error when i try to send message to contacts that are not in my contact list although the user already registered on whatsapp using that number (contact). Here is the message from whatsapp:
here is my code:
try {
Uri uri = Uri.parse("smsto: " + smsNumber);
//Timber.e("smsNumber %s", uri.toString());
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
} catch (Exception e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT).show();
}
is there any solutions ?
you can send via WhatsApp API even if he is not in your contact
String whatsappUrl = String.format("https://api.whatsapp.com/send?phone=%s&text%s",PhoneNumber,msg);
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(whatsappUrl));
browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
p_context.startActivity(browserIntent);

Android -- intent chooser for whatsapp and sms only

I want to create an IntentChooser who offer to share text only via SMS or WhatsApp.
Here is my code to share via WhatsApp:
Intent localIntent = new Intent(Intent.ACTION_SEND);
localIntent.setType("text/plain");
localIntent.setPackage("com.whatsapp");
if (localIntent != null) {
localIntent.putExtra(Intent.EXTRA_TEXT, "Hi there! I'm using this app");
startActivity(Intent.createChooser(localIntent, "Hi there! I'm using this app");
}
I need to add to this also sharing with SMS. How can I do it?
use this for Whatsapp.
try {
startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").setPackage("com.whatsapp").putExtra(Intent.EXTRA_TEXT, Message));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
and this for SMS .
String number = "12346556"; // The number on which you want to send SMS
startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", number, null)));
OR
Possibly Duplicate of Multiple IntentChooser

Sharing a string via telegram messenger

I want to share my string sentence via Telegram messenger so user should select some contacts (or select all option) to sending my pm to them, I use below method to do this work but this action just lets user to selecting one contact for sharing !
void intentMessageTelegram(String msg)
{
final String appName = "org.telegram.messenger";
final boolean isAppInstalled = isAppAvailable(this.getApplicationContext(), appName);
if (isAppInstalled)
{
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
myIntent.setPackage(appName);
myIntent.putExtra(Intent.EXTRA_TEXT, msg);
this.startActivity(Intent.createChooser(myIntent, "Kevin"));
}
else
{
Toast.makeText(this, "Telegram not Installed", Toast.LENGTH_SHORT).show();
}
}
Maybe the URI scheme description will helps you.

Sending message to Multiple Persons using send intent android

I am trying to use the android share intent from my application.
I have listed all the contacts from my contacts content provider in my application.
Now i want to send message to all the contacts i have selected(in my app) using any of the message app
installed in user phone.
I do not want to user smsmaanger , simply want to user any sms sending application in user mobile if
available.
I tried to do with email works great but not with sms .
I tried with email as works great
public static void send(Context ctx, String[] addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
For sms i am using like this .
public static void send(Context ctx, String addy, String subject,
String body,File attachment) {
try {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("vnd.android-dir/mms-sms");
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER,
addy);
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
//sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(attachment));
ctx.startActivity(Intent.createChooser(sendIntent,
"Send via which Application?"));
} catch (Exception e) {
Toast.makeText(ctx, "No activity was found to handle this action",
Toast.LENGTH_SHORT).show();
}
}
I just simply want to add my all contacts to users message app for sending message, with a message
possible
To send SMS to multiple numbers you need to separate the numbers with ;
Sample here:
String toNumbers = "";
ArrayList<String> numbersArrayList;// your phone numbers here
for ( String number : numbersArrayList)
{
toNumbers = toNumbers + number + ";"//separating numbers with semicolon
}
toNumbers = toNumbers.subString(0, toNumbers.length - 1);// remove the last semicolon
...
sendIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER, toNumbers);

Categories

Resources