2013-05-13 83 views
6

我想以編程方式發送MMS我用下面的代碼,它發送彩信編程

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

問題是,它引導到撰寫郵件頁面,需要手動發送短信,我不想這樣,沒有任何它應該發送的通知我該如何做?

有人請分享我的答案

回答

9

我終於找到了一個能100%工作的解決方案。請參閱github項目https://github.com/klinker41/android-smsmms。 (任何人發現它有用,請捐贈給作者http://forum.xda-developers.com/showthread.php?t=2222703)。

通知書的,強制性的設置僅

Settings sendSettings = new Settings(); 

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

你可以讓他們像(在Set APN programmatically on Android發現 - 通過vincent091 answear):

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

我得到這個 java.lang.IllegalArgumentException異常:空郵件URI。 你能幫忙嗎? – user3530687 2017-02-24 05:16:45

-1

通過這種方式,您可以直接彩信,通過給手機號碼和Subject.And附加圖像。

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是Android中一個基於HTTP請求。 您必須擁有移動數據才能發送彩信。 Android沒有公開API發送MMS,因爲它們具有SMS的API。 如果你想要你的應用程序發送彩信,你將不得不寫所有東西。 請參閱AOSP代碼。 https://github.com/android/platform_packages_apps_mms 或者您可以簡單地構建Intent,然後啓動本地消息傳遞應用程序。