0

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

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

我不想使用 smsmaanger ,只想在用户手机中使用任何短信发送应用程序(如果有)。我尝试使用 email 效果很好,但不适用于 sms 。

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

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

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

4

1 回答 1

2

要将 SMS 发送到多个号码,您需要在;
此处使用 Sample 分隔号码:

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);
于 2013-10-22T08:01:26.890 回答