Столкнулся с проблемой - скачивание данных с ММС Центра
Я получаю заголовки и из них извлекаю url хранения ммс и адрес отправителя.
Затем пытаюсь по http скачать данные по url который достал из заголовка.
Но мне возвращается IOException Time Out.
Почему я не могу скачать ммску, стандартное приложение получает ММС.
Ниже код моего ресивера:
Код |
import android.content.BroadcastReceiver; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.Uri; import android.os.Bundle; import android.util.Log; import com.android.mms.transaction.HttpUtils; import com.android.mms.util.SendingProgressTokenManager; import com.google.android.mms.pdu_alt.*;
import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.HashMap; import java.util.Map; import java.util.Set;
/** * Created by Ed on 02.10.2014. */
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; }
}
|