我正在研究多媒體應用程序。我通過相機拍攝了一張圖像,並希望將該圖像以文本發送給其他號碼。但我不知道如何通過MMS發送圖像。如何在Android中通過彩信發送圖像?
回答
這似乎在低位回答:Sending MMS with Android
代碼存在的主要線路:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");
要記住的是圖像應該在外部存儲或作爲內容提供。通常內部應用程序數據不能被其他應用程序訪問。所以你必須暫時寫圖像到外部存儲器,然後將路徑傳遞到'Uri.parse' – Shubhank 2013-05-08 13:18:28
這不再起作用了,因爲在手機中選擇消息活動會使消息僅包含圖片,而不包含文本 – peresisUser 2018-01-31 13:31:46
MMS僅僅是一個HTTTP-POST請求。您應該執行使用額外的網絡功能請求:
final ConnectivityManager connMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
final int result = connMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE, Phone.FEATURE_ENABLE_MMS);
如果你得到結果和Phone.APN_REQUEST_STARTED價值,你必須等待合適的狀態。註冊BroadCastReciver,等到Phone.APN_ALREADY_ACTIVE出現:
final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(reciver, filter);
如果連接後臺準備,構建內容和執行請求。如果您希望使用Android的內部代碼做的,請使用此:
final SendReq sendRequest = new SendReq();
final EncodedStringValue[] sub = EncodedStringValue.extract(subject);
if (sub != null && sub.length > 0) {
sendRequest.setSubject(sub[0]);
}
final EncodedStringValue[] phoneNumbers = EncodedStringValue
.extract(recipient);
if (phoneNumbers != null && phoneNumbers.length > 0) {
sendRequest.addTo(phoneNumbers[0]);
}
final PduBody pduBody = new PduBody();
if (parts != null) {
for (MMSPart part : parts) {
final PduPart partPdu = new PduPart();
partPdu.setName(part.Name.getBytes());
partPdu.setContentType(part.MimeType.getBytes());
partPdu.setData(part.Data);
pduBody.addPart(partPdu);
}
}
sendRequest.setBody(pduBody);
final PduComposer composer = new PduComposer(this.context, sendRequest);
final byte[] bytesToSend = composer.make();
HttpUtils.httpConnection(context, 4444L, MMSCenterUrl,
bytesToSendFromPDU, HttpUtils.HTTP_POST_METHOD, !TextUtils
.isEmpty(MMSProxy), MMSProxy, port);
MMSCenterUrl:從MMS-的APN,端口代理:從MMS-的APN,MMSProxy URL端口從MMS-APN的
注有些類來自內部包。從android git下載是必需的。
的請求應該從用戶的APN空間網址...代碼來完成..:
public class APNHelper {
public class APN {
public String MMSCenterUrl = "";
public String MMSPort = "";
public String MMSProxy = "";
}
public APNHelper(final Context context) {
this.context = context;
}
public List<APN> getMMSApns() {
final Cursor apnCursor = this.context.getContentResolver().query(Uri.withAppendedPath(Telephony.Carriers.CONTENT_URI, "current"), null, null, null, null);
if (apnCursor == null) {
return Collections.EMPTY_LIST;
} else {
final List<APN> results = new ArrayList<APN>();
if (apnCursor.moveToFirst()) {
do {
final String type = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.TYPE));
if (!TextUtils.isEmpty(type) && (type.equalsIgnoreCase(Phone.APN_TYPE_ALL) || type.equalsIgnoreCase(Phone.APN_TYPE_MMS))) {
final String mmsc = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSC));
final String mmsProxy = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPROXY));
final String port = apnCursor.getString(apnCursor.getColumnIndex(Telephony.Carriers.MMSPORT));
final APN apn = new APN();
apn.MMSCenterUrl = mmsc;
apn.MMSProxy = mmsProxy;
apn.MMSPort = port;
results.add(apn);
}
} while (apnCursor.moveToNext());
}
apnCursor.close();
return results;
}
}
private Context context;
}
有人可以解釋如何正確地將所有引用的代碼導入到Eclipse中(例如SendReq類等)?我有git和repo,並且擁有android源代碼,並且在Eclipse中設置了MMS項目(我在SDK中找到了它/ packages/apps/MMS)。但是,它引用了Android系統的很多其他部分,我不知道如何在Eclipse中將所有這些引用放到我的項目中,而無需手動將文件複製到我的項目的src目錄和適當的子目錄中,這是非常困難的。 – 2011-03-16 02:27:27
很多這些類似乎來自非公開的Google API(cfr:Mms應用程序)。我不認爲它們可以用於開箱即用。 – ddewaele 2011-03-27 10:19:17
這段代碼是否調用內置的MMS應用程序? – Vijaya 2011-06-29 11:06:10
如果你有發送彩信使用意圖,然後使用該代碼的任何圖片。
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/image_4.png"));
sendIntent.setType("image/png");
startActivity(sendIntent);;
OR
如果必須使用意圖文件,然後使用該發送彩信與音頻或視頻。
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setClassName("com.android.mms", "com.android.mms.ui.ComposeMessageActivity");
sendIntent.putExtra("address", "1213123123");
sendIntent.putExtra("sms_body", "if you are sending text");
final File file1 = new File(mFileName);
if(file1.exists()){
System.out.println("file is exist");
}
Uri uri = Uri.fromFile(file1);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("video/*");
startActivity(sendIntent);
讓我知道這是否對您有幫助。
在Android 4.0之後,APN助手的答案將不起作用。要獲得Android 4.0及以上版本的mms apn設置,請參閱此答案:View mms apn
- 1. 在Android中捕獲圖像並通過彩信發送
- 2. 通過彩信發送圖像(存儲在繪圖中)
- 3. 通過彩信發送gif
- 4. Android如何發送彩信
- 5. android如何發送短信和彩信?
- 6. 我如何發送文本和圖片(url)通過彩信在android
- 7. 通過彩信發送照片
- 8. 通過http請求發送彩信
- 9. 如何使用Android發送彩信?
- 10. 發送彩信與照片通過HTML鏈接在Android
- 11. 在android中自動發送彩信
- 12. 如何在J2ME中發送彩信?
- 13. Android - 如何通過短信/彩信發送/閱讀電子名片?
- 14. J2ME:通過短信發送圖像
- 15. Android:使用彩信發送本地圖像
- 16. 如何通過編程從iPhone發送彩信?
- 17. android - 在後臺編程發送彩信
- 18. 如何發送彩信中的鏈接?
- 19. 如何在Android 4.0+中使用附加功能發送彩信
- 20. 通過XML從Android發送圖像
- 21. Android:通過POST發送圖像
- 22. 我如何通過android中的活動發送圖像
- 23. 如何通過ajax發送base64圖像
- 24. 如何通過Intent發送base64圖像?
- 25. 如何通過Skype API發送圖像?
- 26. 如何通過axis2發送圖像
- 27. 發送短信和彩信
- 28. 如何在php中通過像素彩色圖像??`
- 29. 使用httpConnection發送彩信(Android 2.1)
- 30. 通過goRPC發送圖像
我正在做類似的事情! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42 2013-01-22 06:33:48