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

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)));
}

Related

Programmatically send SMS message in Android App on tablet without telephony

Trying to send a SMS message through my Android App on a device without telephony like a Tablet without user intervention
Api 23
Would like to either:
1) Find a SMS text program that I incorporate into my Android app to send SMS texts using a device that does not have telephony available - I have no idea if this is possible - have tried to write but haven't figured it out.
OR
2) use a SMS app from the Google play store
I have also tried to send through an app (Textme, WhatsApp, Skype) downloaded from Google Play. I don't seem to be able to fill in the TO field see the code below. Lines that have the // have tried
String strPhone = "92xxxxxxxx";
// Uri sms_uri = Uri.parse("smsto:" + strPhone);
Uri sms_uri = Uri.parse("smsto:+92xxxxxxxx");
// Intent sms_intent = new Intent(Intent.ACTION_SENDTO, sms_uri);
Intent i = new Intent(android.content.Intent.ACTION_SEND, sms_uri);
i.setPackage("com.textmeinc.textme");
// i.putExtra("sms_body", "Greetings!");
i.putExtra("sms_body", "Good Morning ! how r U ?");
i.setType("vnd.android-dir/mms-sms");
// i.putExtra(Intent.EXTRA_SUBJECT,"92xxxxxxxx");
i.putExtra("address", "92xxxxxxxx");
i.putExtra(Intent.EXTRA_TEXT, "Hi from me");
// i.putExtra(Intent.EXTRA_PHONE_NUMBER, strPhone);
// i.putExtra(Insert.PHONE, "92xxxxxxxx");
// i.putExtra(ContactsContract.Intents.Insert.PHONE, "(408) 555-1212");
// i.setData(Uri.parse("tel:" + strPhone));
i.setData(Uri.parse("sms:" + strPhone));
i.setType("text/plain");
// i.setType("vnd.android-dir/mms-sms"); does not work
BT_debugger.showIt( "textme" );
i.putExtra("chat",true);
i.putExtra("sms_body", "test");
try {
BT_debugger.showIt( "textme sms found" );
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
BT_debugger.showIt( "textme sms not found" );
}

Send SMS to multiple phone number when messenger is set as default sms app in android

I have implemented the ability to send message in my app and it is working well. But if the user is using another sms app like messenger as their default sms app then, I can't send message to multiple recipients.
If multiple phone number is selected, only one of them get the message in most cases the last phone number.
NOTE: I'm using an implicit intent to send the message and it can send to multiple recipients on stock sms app.
Any help will ve greatly appreciated.
This is what I have as requested
Intent intent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
String defaultSmsPackage = Telephony.Sms.getDefaultSmsPackage(getActivity());
if (defaultSmsPackage != null) {
intent.setPackage(defaultSmsPackage);
}
} else {
Uri numbersUri = Uri.parse("tel:" + phoneNumbers);
intent = new Intent(Intent.ACTION_VIEW, numbersUri);
intent.setType("vnd.android-dir/mms-sms");
}
intent.putExtra("address", phoneNumbers);
intent.putExtra("sms_body", message);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
}

Choose among SMS, WhatsApp, or Telegram to send message

At a contact list in my Android app, there is an option to launch WhatsApp implemented as follows:
// Country code is required
final String phoneNumber = "+15555555555";
final String packageName = "com.whatsapp";
Intent intent = getPackageManager().getLaunchIntentForPackage(packageName);
if (null == intent) {
// Launch Google Play at WhatsApp homepage
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://details?id=" + MESSAGE_PACKAGE_NAME));
startActivity(intent);
return;
}
intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));
intent.setPackage(packageName);
startActivity(intent);
but this only allow me to send messages through WhatsApp.
Removing the package name and setting the intent type to
intent.setType("vnd.android-dir/mms-sms");
launched the SMS application.
How can we choose among all apps installed at an Android device that use the phone number as and identifier (Hangouts, SMS, Skype, Line, Telegram, Viber, WhatsApp, etc)?
Fortunately Android Intent.createChooser is smart enough to figure out the apps that understand the phone numbers as an identifier :-)
// Country code is required
String phoneNumber = "+15555555555";
Uri uri = Uri.parse("smsto:" + phoneNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
startActivity(Intent.createChooser(intent, "Send message"));

Share data with WhatsApp

I'm wondering if I can send text data from my Android application to WhatsApp without showing the contacts list of WhatsApp, I just need to set the message and the mobile number internally in my Android code?
You can try something like this:
public void sendWhatsappMessageToMsisdn(String contactNumber)
{
Uri uri = Uri.parse("smsto:" + contactNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "This is the message you want to send");
startActivity(Intent.createChooser(intent, ""));
}

How to show the dialog of all the messaging options in android?

I am trying to send text messages to the selected contacts on the phone using the SmsManager but by default it sends the message using the phone GSM message option. My requirement is to show the popup to the user to choose is messaging options such as WHATSAPP, VIBER etc as shown in the image
here is my code
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage("9844598445", null, "Hello There", null, null);
Please help
Try this one
Uri uri = Uri.parse("smsto:" + smsNumber);
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", smsText);
startActivity(intent);
What you're doing right now is directly send an SMS through the SDK. If you want to offer the user the option to send it through another installed app, you need to use an Intent:
Uri uri = Uri.parse("smsto:1234567890");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);

Categories

Resources