从我的Android应用程序发送彩信 [英] Send MMS from My application in android
问题描述
我想从我的应用程序发送彩信给一个具体的数字。我搜索,发现这个code,但我不知道,如果这code我需要什么或没有。 我的问题是:
I want to send MMS from my application to a specific number. I've searched and found this code but I have no idea if this code what I need or not. My Questions is :
- 可谁能解释这code到我,我是初学者彩信。
-can anyone explain this code to me.i am beginner in MMS.
- 也,我认为这code为让用户从我的应用程序发送彩信,而不将其移动到本地信息的收件箱(这就是我想要的)是正确的?我
-also, i thought this code is let the user send MMS from my application without move it to the native Messaging inbox (and this is what i want) Am i right?
- 也我有一个问题,我不知道我怎样才能把这个code在我的项目。
-also i have a problem ,i do not know how can i put this code in my project.
这是我发现
彩信仅仅是一个HTTP-POST请求。你应该使用额外的网络功能执行请求:
MMS is just a http-post request. You should perform the request using extra network feature :
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
显示:
If you get back the result with Phone.APN_REQUEST_STARTED
value, you have to wait for proper state. Register BroadCastReciver
and wait until Phone.APN_ALREADY_ACTIVE
appears:
final IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
context.registerReceiver(reciver, filter);
如果后台连接已准备就绪,然后生成内容和执行请求。如果你想这样做,使用Android的内部code,请使用此:
If background connection is ready, then build content and perform request. If you want to do that using android's internal code, please use this:
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从彩信的APN,
- MMSProxy:由彩信的APN的代理,
- 端口:从彩信的APN端口
请注意,某些类是内部的包。下载从Android的Git是必需的。 申请应与URL从用户的APN空间code来完成:
Note that some classes are from internal packages. Download from android git is required. The request should be done with url from user's apn-space code:
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;
}
请帮我
推荐答案
这篇博客文章[1]和下面的评论回答您的问题
this blog post[1] and the comments below answer all your questions
[1]的http://androidbridge.blogspot.de/2011/03/how-to-send-mms-programmatically-in.html
这篇关于从我的Android应用程序发送彩信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!