【问题标题】:Sending message to Multiple Persons using send intent android使用发送意图android向多人发送消息
【发布时间】:2013-10-22 16:01:26
【问题描述】:

我正在尝试使用我的应用程序中的 android 共享意图。

我已在我的应用程序中列出了来自我的联系人内容提供商的所有联系人。 现在我想使用任何消息应用程序向我选择的所有联系人(在我的应用程序中)发送消息 安装在用户手机中。

我不想使用 smsmaanger ,只是想在用户手机中使用任何短信发送应用程序,如果 可用的。 我尝试使用电子邮件效果很好,但不适用于短信。

我尝试使用电子邮件,效果很好

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

对于短信我是这样使用的。

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

我只是想将我的所有联系人添加到用户消息应用程序以发送消息,并带有消息 可能

【问题讨论】:

标签: android android-intent


【解决方案1】:

要向多个号码发送短信,您需要用;分隔号码
示例:

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

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 1970-01-01
    • 2012-04-14
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 2014-02-21
    相关资源
    最近更新 更多