2013-05-13 23 views
6

Tôi muốn gửi tin nhắn MMS lập trình tôi đã sử dụng đoạn mã sau cho nóGửi MMS lập trình

Intent sendIntent1 = new Intent(Intent.ACTION_SEND); 
    try { 

     sendIntent1.setType("text/x-vcard"); 
     sendIntent1.putExtra("address","0475223091"); 
     sendIntent1.putExtra("sms_body","hello.."); 
     sendIntent1.putExtra(Intent.EXTRA_STREAM, 
       Uri.parse(vcfFile.toURL().toString())); 
    } catch (MalformedURLException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    startActivity(sendIntent1); 

Vấn đề là nó hướng đến trang soạn tin nhắn và đòi hỏi tay gửi tin nhắn SMS và tôi không muốn như vậy mà không bất kỳ thông báo nó nên gửi Làm thế nào tôi có thể làm điều đó ??

SomeBody vui lòng chia sẻ cho tôi câu trả lời

Trả lời

9

Cuối cùng tôi đã tìm được giải pháp hoạt động 100%. Vui lòng tham khảo dự án github https://github.com/klinker41/android-smsmms. (Bất cứ ai tìm thấy nó hữu ích xin vui lòng tặng cho tác giả http://forum.xda-developers.com/showthread.php?t=2222703).

Thông báo, rằng các thiết lập bắt buộc chỉ

Settings sendSettings = new Settings(); 

sendSettings.setMmsc(mmsc); 
sendSettings.setProxy(proxy); 
sendSettings.setPort(port); 

bạn có thể nhận được chúng một cái gì đó tương tự (tìm thấy tại Set APN programmatically on Android - answear bởi vincent091):

Cursor cursor = null; 
if (Utils.hasICS()){ 
    cursor =SqliteWrapper.query(activity, activity.getContentResolver(), 
      Uri.withAppendedPath(Carriers.CONTENT_URI, "current"), APN_PROJECTION, null, null, null); 
} else { 
    cursor = activity.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), 
     null, null, null, null); 
} 

cursor.moveToLast(); 
String type = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.TYPE)); 
String mmsc = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSC)); 
String proxy = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPROXY)); 
String port = cursor.getString(cursor.getColumnIndex(Telephony.Carriers.MMSPORT)); 
+0

tôi nhận được java.lang.IllegalArgumentException này: URI tin nhắn rỗng. Bạn có thể trợ giúp không? – user3530687

-1

Bằng cách này bạn có thể mms trực tiếp, Bằng cách cho điện thoại di động No và Subject.And đính kèm hình ảnh.

Uri uri = Uri.parse("file://"+Environment.getExternalStorageDirectory()+"/test.png"); 
     Intent i = new Intent(Intent.ACTION_SEND); 
     i.putExtra("address","1234567890"); 
     i.putExtra("sms_body","This is the text mms"); 
     i.putExtra(Intent.EXTRA_STREAM,"file:/"+uri); 
     i.setType("image/png"); 
     startActivity(i); 
2

MMS là yêu cầu dựa trên HTTP trong Android. Bạn phải có dữ liệu di động để gửi MMS. Không có API nào được Android tiếp xúc để gửi MMS vì chúng có API cho SMS. Nếu bạn muốn ứng dụng của mình gửi MMS, bạn sẽ phải viết mọi thứ. Vui lòng tham khảo mã AOSP. https://github.com/android/platform_packages_apps_mms HOẶC bạn chỉ cần xây dựng Mục đích và sau đó khởi chạy Ứng dụng nhắn tin gốc.