我遇到了一个我应该做的任务的问题, 我应该在android 2.1上使用我们自己的界面发送彩信 所以你可以猜测调用默认的Activity是不可能的。 所以我的问题是,有没有办法以编程方式使用android SDK发送彩信 没有说出他们的意图, 我尝试在eclipse中导入MMS应用程序,但大多数类都是com.google.android 这意味着它们不是开源的,所以我不知道如果可能的话如何获得它们, 或者,如何模仿他们。我甚至考虑使用反射从Dalvik加载它们,但我认为这是最后的努力,可能不会带来结果。
任何想法?
顺便说一下,我找到了How to send image via MMS in Android?
Sending MMS into different Android devices
但它们不起作用..(没有专有类)
答案 0 :(得分:2)
虽然这个问题在一段时间内没有得到答案,但我当时找到了一条路,只是忘了张贴。 然而,我得到了原始的MMS应用程序,并削弱了二进制类,并添加了相应的要求,因为大多数是私有的构建系统。 唯一的方法是使android中的mms发送者(我知道)是使用源树构建应用程序。通过这种方式,您可以访问受限制的MMS功能,并且通常非常容易,因为它自己的源中有一个MMSManager,尽管这在sdk中不公开。 我知道我的答案有点模糊,但是对于那些沿着这条路走下去的人......准备在路上遇到一些颠簸.. :)
答案 1 :(得分:0)
像SmsManager一样,MmsManager api之类的东西也没有被Android框架公开。
因此要首先发送MMS,您必须先获得MMS netwotk,然后进行http呼叫。
/**
* Synchronously acquire MMS network connectivity
*
* @throws MmsNetworkException If failed permanently or timed out
*/
void acquireNetwork() throws MmsNetworkException {
Log.i(MmsService.TAG, "Acquire MMS network");
synchronized (this) {
try {
mUseCount++;
mWaitCount++;
if (mWaitCount == 1) {
// Register the receiver for the first waiting request
registerConnectivityChangeReceiverLocked();
}
long waitMs = sNetworkAcquireTimeoutMs;
final long beginMs = SystemClock.elapsedRealtime();
do {
if (!isMobileDataEnabled()) {
// Fast fail if mobile data is not enabled
throw new MmsNetworkException("Mobile data is disabled");
}
// Always try to extend and check the MMS network connectivity
// before we start waiting to make sure we don't miss the change
// of MMS connectivity. As one example, some devices fail to send
// connectivity change intent. So this would make sure we catch
// the state change.
if (extendMmsConnectivityLocked()) {
// Connected
return;
}
try {
wait(Math.min(waitMs, NETWORK_ACQUIRE_WAIT_INTERVAL_MS));
} catch (final InterruptedException e) {
Log.w(MmsService.TAG, "Unexpected exception", e);
}
// Calculate the remaining time to wait
waitMs = sNetworkAcquireTimeoutMs - (SystemClock.elapsedRealtime() - beginMs);
} while (waitMs > 0);
// Last check
if (extendMmsConnectivityLocked()) {
return;
} else {
// Reaching here means timed out.
throw new MmsNetworkException("Acquiring MMS network timed out");
}
} finally {
mWaitCount--;
if (mWaitCount == 0) {
// Receiver is used to listen to connectivity change and unblock
// the waiting requests. If nobody's waiting on change, there is
// no need for the receiver. The auto extension timer will try
// to maintain the connectivity periodically.
unregisterConnectivityChangeReceiverLocked();
}
}
}
}
这是我从android本机源代码获得的代码的宁静。
/**
* Run the MMS request.
*
* @param context the context to use
* @param networkManager the MmsNetworkManager to use to setup MMS network
* @param apnSettingsLoader the APN loader
* @param carrierConfigValuesLoader the carrier config loader
* @param userAgentInfoLoader the user agent info loader
*/
public void sendMms(final Context context, final MmsNetworkManager networkManager,
final ApnSettingsLoader apnSettingsLoader,
final CarrierConfigValuesLoader carrierConfigValuesLoader,
final UserAgentInfoLoader userAgentInfoLoader) {
Log.i(MmsService.TAG, "Execute " + this.getClass().getSimpleName());
int result = SmsManager.MMS_ERROR_UNSPECIFIED;
int httpStatusCode = 0;
byte[] response = null;
final Bundle mmsConfig = carrierConfigValuesLoader.get(MmsManager.DEFAULT_SUB_ID);
if (mmsConfig == null) {
Log.e(MmsService.TAG, "Failed to load carrier configuration values");
result = SmsManager.MMS_ERROR_CONFIGURATION_ERROR;
} else if (!loadRequest(context, mmsConfig)) {
Log.e(MmsService.TAG, "Failed to load PDU");
result = SmsManager.MMS_ERROR_IO_ERROR;
} else {
// Everything's OK. Now execute the request.
try {
// Acquire the MMS network
networkManager.acquireNetwork();
// Load the potential APNs. In most cases there should be only one APN available.
// On some devices on which we can't obtain APN from system, we look up our own
// APN list. Since we don't have exact information, we may get a list of potential
// APNs to try. Whenever we found a successful APN, we signal it and return.
final String apnName = networkManager.getApnName();
final List<ApnSettingsLoader.Apn> apns = apnSettingsLoader.get(apnName);
if (apns.size() < 1) {
throw new ApnException("No valid APN");
} else {
Log.d(MmsService.TAG, "Trying " + apns.size() + " APNs");
}
final String userAgent = userAgentInfoLoader.getUserAgent();
final String uaProfUrl = userAgentInfoLoader.getUAProfUrl();
MmsHttpException lastException = null;
for (ApnSettingsLoader.Apn apn : apns) {
Log.i(MmsService.TAG, "Using APN ["
+ "MMSC=" + apn.getMmsc() + ", "
+ "PROXY=" + apn.getMmsProxy() + ", "
+ "PORT=" + apn.getMmsProxyPort() + "]");
try {
final String url = getHttpRequestUrl(apn);
// Request a global route for the host to connect
requestRoute(networkManager.getConnectivityManager(), apn, url);
// Perform the HTTP request
response = doHttp(
context, networkManager, apn, mmsConfig, userAgent, uaProfUrl);
// Additional check of whether this is a success
if (isWrongApnResponse(response, mmsConfig)) {
throw new MmsHttpException(0/*statusCode*/, "Invalid sending address");
}
// Notify APN loader this is a valid APN
apn.setSuccess();
result = Activity.RESULT_OK;
break;
} catch (MmsHttpException e) {
Log.w(MmsService.TAG, "HTTP or network failure", e);
lastException = e;
}
}
if (lastException != null) {
throw lastException;
}
} catch (ApnException e) {
Log.e(MmsService.TAG, "MmsRequest: APN failure", e);
result = SmsManager.MMS_ERROR_INVALID_APN;
} catch (MmsNetworkException e) {
Log.e(MmsService.TAG, "MmsRequest: MMS network acquiring failure", e);
result = SmsManager.MMS_ERROR_UNABLE_CONNECT_MMS;
} catch (MmsHttpException e) {
Log.e(MmsService.TAG, "MmsRequest: HTTP or network I/O failure", e);
result = SmsManager.MMS_ERROR_HTTP_FAILURE;
httpStatusCode = e.getStatusCode();
} catch (Exception e) {
Log.e(MmsService.TAG, "MmsRequest: unexpected failure", e);
result = SmsManager.MMS_ERROR_UNSPECIFIED;
} finally {
// Release MMS network
networkManager.releaseNetwork();
}
}
// Process result and send back via PendingIntent
returnResult(context, result, response, httpStatusCode);
}
/**
* Request the route to the APN (either proxy host or the MMSC host)
*
* @param connectivityManager the ConnectivityManager to use
* @param apn the current APN
* @param url the URL to connect to
* @throws MmsHttpException for unknown host or route failure
*/
private static void requestRoute(final ConnectivityManager connectivityManager,
final ApnSettingsLoader.Apn apn, final String url) throws MmsHttpException {
String host = apn.getMmsProxy();
if (TextUtils.isEmpty(host)) {
final Uri uri = Uri.parse(url);
host = uri.getHost();
}
boolean success = false;
// Request route to all resolved host addresses
try {
for (final InetAddress addr : InetAddress.getAllByName(host)) {
final boolean requested = requestRouteToHostAddress(connectivityManager, addr);
if (requested) {
success = true;
Log.i(MmsService.TAG, "Requested route to " + addr);
} else {
Log.i(MmsService.TAG, "Could not requested route to " + addr);
}
}
if (!success) {
throw new MmsHttpException(0/*statusCode*/, "No route requested");
}
} catch (UnknownHostException e) {
Log.w(MmsService.TAG, "Unknown host " + host);
throw new MmsHttpException(0/*statusCode*/, "Unknown host");
}
}
答案 2 :(得分:-6)
private void sendSMS(String phoneNumber, String message)
{
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SMS.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, pi, null);
}
}
试试这个