Sending a message to multiple people using the android send

I am trying to use share android intent for my application.

I have listed all the contacts from my contact content provider in my application. Now I want to send a message to all the contacts that I have selected (in my application) using any message application installed on the user's phone.

I do not want the smsmaanger user, I just want the sms user to send the application on the mobile phone, if available. I tried to work with email, excellent, but not with SMS.

I tried email, how great it works

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 use 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 want to add all my contacts to the message application to send a message with a message maybe

0
1

SMS , ;
:

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);
+2

Source: https://habr.com/ru/post/1687196/


All Articles