I can not download the data from the MMS center. Then try on http download data url that took out PduHeaders. But I returned IOException Time Out. Why can not I download MMS, standard application receives MMS
public class MMSReceiver extends BroadcastReceiver {
Context context;
ConnectivityManager manager;
public void onReceive(final Context context, Intent intent) {
this.context = context;
Bundle bundle = intent.getExtras();
manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
byte[] buffer = bundle.getByteArray("data");
GenericPdu genericPdu = new PduParser(buffer).parse();
ContentValues vl = getParams(genericPdu);
final String contentLocation = vl.getAsString("ct_l");
new Thread(new Runnable() {
@Override
public void run() {
try {
ensureRouteToHost(context, contentLocation, "10.10.10.10");
byte[] rawPdu = HttpUtils.httpConnection(context, SendingProgressTokenManager.NO_TOKEN, contentLocation, null, HttpUtils.HTTP_GET_METHOD, true, "10.10.10.10", 8080); // ЗДЕСЬ <====================
Log.i("mLogs", "DATA :" + rawPdu.length);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
public static void ensureRouteToHost(Context context, String url, String proxy) throws IOException {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
connMgr.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE_HIPRI, "enableMMS");
int inetAddr;
if (proxy != null && !proxy.equals("")) {
String proxyAddr = proxy;
inetAddr = lookupHost(proxyAddr);
if (inetAddr == -1) {
Log.i("mLogs", "Cannot establish route for " + url + ": Unknown host");
} else {
if (!connMgr.requestRouteToHost(ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
Log.i("mLogs","Cannot establish route to proxy " + inetAddr);
}
}
} else {
Uri uri = Uri.parse(url);
inetAddr = lookupHost(uri.getHost());
if (inetAddr == -1) {
throw new IOException("Cannot establish route for " + url + ": Unknown host");
} else {
if (!connMgr.requestRouteToHost( ConnectivityManager.TYPE_MOBILE_MMS, inetAddr)) {
throw new IOException("Cannot establish route to " + inetAddr + " for " + url);
}
}
}
}
private static int lookupHost(String hostname) {
InetAddress inetAddress;
try {
inetAddress = InetAddress.getByName(hostname);
} catch (UnknownHostException e) {
return -1;
}
byte[] addrBytes;
int addr;
addrBytes = inetAddress.getAddress();
addr = ((addrBytes[3] & 0xff) << 24) | ((addrBytes[2] & 0xff) << 16) | ((addrBytes[1] & 0xff) << 8) | (addrBytes[0] & 0xff);
return addr;
}
0 comments:
Post a Comment