我想从我的应用程序发送彩信到一个特定的号码。我搜索并找到了这段代码,但是我不知道这段代码是否需要。 我的问题是:发送彩信从我的应用程序在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