[英]Send MMS programmatically
我想以編程方式發送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);
問題是它指向撰寫消息頁面,並需要手動發送短信,我不想這樣,沒有任何通知它應該發送我怎么能這樣做?
SomeBody請與我分享答案
我終於找到了一個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);
你可以得到類似的東西(通過vincent091 在Android上以編程方式找到Set APN ):
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));
MMS是Android中基於HTTP的請求。 您必須擁有移動數據才能發送彩信。 Android沒有公開發送MMS的API,因為它們有用於SMS的API。 如果您希望您的應用程序發送彩信,您將必須編寫所有內容。 請參閱AOSP代碼。 https://github.com/android/platform_packages_apps_mms或者您可以簡單地構建Intent,然后啟動本機Messaging App。
通過這種方式你可以直接mms,給手機號碼和主題。並附加圖像。
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.