Title is obvious. Can I send "SMS received intent" on the android phone? In other words, virtually receive custom SMS to fake some SMS receivers.
You can create fake SMS (GMS type) so built-in catch like real message. Here is my answer
Intent intent = new Intent();
intent.setClassName("com.android.mms",
"com.android.mms.transaction.SmsReceiverService");
intent.setAction("android.provider.Telephony.SMS_RECEIVED");
intent.putExtra("pdus", new Object[] { pdu });
intent.putExtra("format", "3gpp");
context.startService(intent);
Related
I know since KitKat the code to start the SMS app is the following:
String default_sms_package_name = Telephony.Sms.getDefaultSmsPackage(context);
intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, body);
if (default_sms_package_name != null) intent.setPackage(default_sms_package_name);
But is there a way to preselect the SMS receiver like the SMS body?
Yes you can use ACTION_VIEW and set as many numbers as you want with address parameter as below.
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("smsto:"));
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address" , new String("0123456789;3393993300"));
smsIntent.putExtra("sms_body" , "Test SMS to Angilla");
startActivity(smsIntent);
this is going to be a newbie question, but I'm curious how Intent's ACTION_SENDTO works. The code is like this:
TextView textView = (TextView) findViewById(R.id.number_to_call);
String smsNumber = String.format("smsto: %s", textView.getText().toString());
EditText smsEditText = (EditText) findViewById(R.id.sms_message);
String sms = smsEditText.getText().toString();
Intent smsIntent = new Intent(Intent.ACTION_SENDTO);
smsIntent.setData(Uri.parse(smsNumber));
smsIntent.putExtra("sms_body", sms);
I understand that:
This is an implicit intent
ACTION_SENDTO is the action of the intent
setData takes in data of the intent
But whatever in putExtra, I guess what it does is putting in "extra" data? Immediate after running this intent, it takes me to a normal Messages app with number as smsNumber, and sms as content. My questions are:
How does the intent "know" smsNumber should be in the phone number section, and sms is in content section?
I also guess the name "sms_body" does affect the role of the data after it (aka sms is the content of message)?
Edit: I found an explanation for this. It should be in Common Intents
You can use "smsto:XXXXXXXXXX" in uri to give the phone number like in this example from the post :
ACTION_SEND used to send sms
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
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);
}
I am trying to send a SMS through an intent, I want to add a body to the message. After user press send I want to return to the app. I've added extra as sms_body and exit_on_sent. But when I use them both the SMS appears without the body. If i don't use the exit_on_sent extra everything works fine.
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("smsto:" + phoneNumber));
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra("exit_on_sent", true);
context.startActivity(sendIntent);
You could try using
startActivityForResult(sendIntent, SOME_REQUEST_CODE)
but in my experience it doesn't works most of the time.
I would recommend instead using SmsManager.
SmsManager smsMgr = SmsManager.getDefault();
if(smsMgr != null){
PendingIntent sentIntent = PendingIntent.getBroadcast(
getActivity().getApplicationContext(), 0,
new Intent(MY_ACTION_INTENT_SENT), 0);
smsMgr.sendTextMessage(phone, null, message, sentIntent, null);
}
Depending on your application you can do the rest of processing when MY_ACTION_INTENT is sent (indicating the message has actually been sent) or right after sendTextMessage(...) returns.
From API Level 19 there are some interesting features you may found useful http://developer.android.com/reference/android/provider/Telephony.html
Hope it helps.
How to send a SMS to many recipients in android? I want to send a SMS to many receivers in my application. I know this code:
Uri smsToUri = Uri.parse("smsto:" + 10086);
Intent intent = new Intent(
android.content.Intent.ACTION_SENDTO, smsToUri);
String message = "hello";
// message = message.replace("%s", StoresMessage.m_storeName);
intent.putExtra("sms_body", message);
startActivity(intent);
This work for single recipient. But How to send the message to many recipients by using "ACTION_SENDTO" intent? That is too say, how to call the third-party application to send a SMS to many recipients in phone?
send sms to multiple numbers:
String strnum="10086;10086;10087;10089";
Uri smsToUri = Uri.parse("smsto:" + strnum);
or for Sending SMS to Multiple numbers using SmsManager see this post
Unable to send sms using SmsManager in Android