How can I send individual SMS to multiple recipients using an Intent only? (no SMSManager!) Is this even possible? I have tried the following solution but it creates a group message (MMS):
private void sendSMS(String[] phoneNumbers, String message){
StringBuilder sb = new StringBuilder();
for (String s :
phoneNumbers) {
sb.append(s);
sb.append(";");
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("smsto:" + sb.toString())); // This ensures only SMS apps respond
intent.putExtra("sms_body", message);
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(intent);
}
}
Again, the goal is to send a text to each recipient individually, not as a group message. I cannot use SMSManager because as of 2019 the Google Play Store prohibits sending SMS unless your app is the default messaging app (with some exceptions).
Related
I have created an android application that listens for incoming sms. The issue i am encountering is that it also reads previous sms. The goal of the app was to grab sms from a specific originating address and store it in a database.
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.i(TAG, "Intent Received: "+intent.getAction());
if (intent.getAction()==SMS_RECEIVED){
Bundle dataBundle = intent.getExtras();
if(dataBundle != null){
//creating PDU protocol Data unit object which is a protocol for transferring message
Object[] mypdu = (Object[])dataBundle.get("pdus");
final SmsMessage[] message = new SmsMessage[mypdu.length];
for(int i =0; i< mypdu.length; i++){
//for build version >= API
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
String format = dataBundle.getString("format");
//From PDU we get all object and smsMessage using following line of code
message[i] = SmsMessage.createFromPdu((byte[])mypdu[i],format);
}else{
message[i] = SmsMessage.createFromPdu((byte[]) mypdu[i]);
}
msg += message[i].getMessageBody().toString().replace("null","");
originatingAddress = message[i].getOriginatingAddress();
}
msg = msg.replace("null","");
if(originatingAddress.trim().equals("MPESA")) {
Toast.makeText(context.getApplicationContext(), "message: " + msg, Toast.LENGTH_SHORT).show();
}
}
}
// throw new UnsupportedOperationException("Not yet implemented");
}
}
Please try with below way
(1)The Simple way you can achieve to store the unique of record on every SMS is timestamp is only unique in this case whenever you get SMS store timestamp of every Sms as a Unique or primary key as you want in database, like system.currentTimeMillisecond to get time of current SMS and store as LONG type Column in your database,
(2) you can also check with unique time on every SMS get but it is complex to check with every existing records
Hope this process will help in your way with prevent of duplicate record store in database
I have an auto reply sms Android application I built and I don't want the auto reply (sent sms) to show in the default messaging app. I have searched and searched and couldn't find an answer. Is there a way to bypass writing the sent sms into the default messaging app?
Here my BroadcastReciever I am using to get the data and send out the message
public class SmsReceiver extends BroadcastReceiver {
ParseUser user = ParseUser.getCurrentUser();
// Auto reply message composed of the current reply and url from that business
String msg = user.getString("myCurrentReply") + " " + user.getString("couponUrlChosen");
List smsFromList = user.getList("smsFrom");
String userName = (String) user.get("username");
#Override
public void onReceive(final Context context, Intent intent) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
final String pno = smsMessage[0].getOriginatingAddress();
user.put("lastSmsFrom", pno);
user.saveInBackground();
// show first message
Toast toast = Toast.makeText(context, "Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
// Check Phone Number from SMS Received against Array in User Row
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
Log.d("Username: ", userName);
query.whereEqualTo("username", userName);
query.whereContainedIn("lastSmsFrom", smsFromList);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> smsList, ParseException e) {
if (e == null) {
Log.d("Errors", "none");
if (smsList.size() == 0) {
// Send SMS
sendSms(pno, msg);
// Add Phone number to smsFrom in currentUsers Row
user.addUnique("smsFrom", pno);
// Save Phone Number in Array
user.saveInBackground();
Log.d("List size: ", " " + smsList.size());
}
} else {
Log.d("Error Message: ",
e.getMessage());
}
Log.d("Already sent to this number today. ", " " + smsList.size());
}
});
}
private void sendSms(String phonenumber, String message) {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage(phonenumber, null, message, null, null);
}
}
Prior to KitKat, SMS sent using SmsManager require the app sending the message to insert it into the Provider, so it would just be a matter of omitting that.
Starting with KitKat, any app that is not the default SMS app and uses SmsManager to send messages will have the messages automatically written to the Provider for it by the system. There's no way to prevent this, and, furthermore, the app won't be able to delete those messages, either, as it won't have write access to the Provider.*
The app that is the default SMS app is responsible for writing its outgoing messages, so it would be able to omit that step. The system does no automatic writes for the default SMS app.
* There is a security hole in 4.4 only, by which a non-default app can gain write access to the Provider. It is detailed in my answer here, but it will not work in versions after KitKat.
This question already has answers here:
send data to email in background
(3 answers)
Closed 6 years ago.
i was creating Android Intent Mail. i am getting all the subject, to , mail body in email. is there is any possibility to send the mail without pressing send button .
My code is :
public void Sendmail(HashMap s) {
HashMap<String, String> sss = s;
String[] toppings = new String[sss.size()];
int size1 = 0;
for (String key : sss.keySet()) {
toppings[size1] = key + "\n" + sss.get(key) + "\n";
System.out.println("key: " + key + " value: " + sss.get(key));
size1++;
}
StringBuilder builder = new StringBuilder();
for (String s3 : toppings) {
builder.append(s3);
}
String mbody = builder.toString();
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("plain/text");
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Task Activity");
i.putExtra(android.content.Intent.EXTRA_TEXT, mbody);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"hari.andoidsaiss#gmail.com"});
try {
startActivity(i);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Main2Activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
You can't do it. A user should know what he is sending. Also a user should be aware about his actions.
You can do it using API and sending Email from server.
You can't do it with Share Intent of Android as it will populate installed app from your device which can process your data.
You can achieve this by following ways:
Implement mail client to send emails from your server side. ex: mailgun.
Integrate API's like Javamail or Gmail to your android app to get your work done.
Using Android 5.1 on Nexus tablet that doesn't have native SMS capabilities.
I am trying to use Google Messenger to send a SMS text from the tablet via an Android App without intervention.
Google Messenger is installed and I do get the Toast that the message has been sent.
However I don't get a text message to the phone I am trying to send to
AND
the Test Text appears and stays stuck on the screen and the app doesn't go back its normal processing.
------------ Code I am using but I have replaced the phone number -----------
public void sendMessenger(String phoneNo, String message) {
Uri uri = Uri.parse("smsto:5555555555");
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
waIntent.setClassName("com.google.android.apps.messaging", "com.google.android.apps.messaging.Main");
waIntent.setType("text/plain");
String text = "testing message";
waIntent.setPackage("com.google.android.apps.messaging");
if (waIntent != null) {
waIntent.putExtra("address", "5555555555");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
waIntent.putExtra("sms_body", "HI");
startActivity(Intent.createChooser(waIntent, text));
Toast.makeText(getActivity(), "Message Sent",Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "Google Messenger NOT Installed!",Toast.LENGTH_SHORT).show();
}
I want to open incoming sms from notification directly to my application's intent , Please help I tried following code to read sms from inbox
public class SmsReceiver extends BroadcastReceiver
{
public static String BODY = "Test";
public static String ADDRESS = "5556";
#Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
ADDRESS=msgs[i].getOriginatingAddress();
BODY=str;
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
When a new SMS is received by your device, the android creates a intent and broadcasts the SMS_RECEIVED_ACTION. What you are going to do is create an Intent Filter for the activity of your application that handles the SMS that the phone receives.
When the phone gets a new SMS message and the user clicks on the notification, she is presented with a dialog of apps that can handle this action*****. Your app should be there, and when she decides that she wants your app to handle the incoming message then you can use the getMessagesFromIntent method in order to extract the message (you use that method inside your app).
PS: You cannot set your app as the default message app, which you probably need to do. The user has to explicitly choose your app to open the message, and if she wants it to be the default messaging app (by ticking the set as default checkbox).
Note: It looks like you have to create a broadcast receiver that receives the SMS_RECEIVED_ACTION which you can use prior to API 19 as a constant at android.provider.Telephony.SMS_RECEIVED and launch your own notifications in which you direct the user directly to the application of yours. Unfortunately it seems that the default messaging app will still issue notifications.
Credit: #Mike M.