2013-10-22 110 views
0

我想从我的应用程序中使用android共享意图。使用发送意向向多人发送消息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(); 
    } 
} 

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

+1

尝试下面粘贴的链接。 [发送短信到多个联系人。] [1] [1]:http://stackoverflow.com/questions/16771470/android-send-sms-to-multiple-contacts-using-arraylist – OAEI

+0

@TrushitShah是的哥们非常有帮助的链接谢谢 – Bora

回答

2

消息要发送短信到你需要的数字与;
样品中分离多个号码在这里:

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

感谢哥们,工作 – Bora