我想從我的應用程序發送彩信到一個特定的號碼。我搜索並找到了這段代碼,但是我不知道這段代碼是否需要。 我的問題是:發送彩信從我的應用程序在Android
- 任何人都可以解釋這段代碼給我,我是初學者在MMS。
- 另外,我認爲這個代碼是讓用戶從我的應用程序發送彩信,而不必將其移動到本地消息收件箱(這是我想要的)我是對的嗎?
- 另外我有一個問題,我不知道我怎麼能把這段代碼放到我的項目中。
這就是我發現的
MMS只是一個http發佈請求。你應該使用額外的網絡功能執行請求:
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:URL從MMS-的APN,
- MMSProxy:從MMS-APN的代理,
- 端口:端口從MMS-APNs
請注意,有些類來自內部包。從android git下載是必需的。 請求應與URL進行從用戶的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>();
while (apnCursor.moveToNext()) {
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);
}
}
apnCursor.close();
return results;
}
請幫我
我做類似的東西在這裏! http://stackoverflow.com/questions/14452808/sending-and-receiving-mms-in-android – toobsco42 2013-01-22 06:36:56
Pleae指我的答案在這裏http://stackoverflow.com/a/20611335/2422453 – Defuera 2013-12-16 12:49:38
喊叫沒有答案沒有得到一個答案 :/ – 2016-08-05 18:27:27