Reputation: 5363
I need to make HTTP request on Android using GSM connection, not Wifi.
My current solution is to disconnect from all wi-fi connections and perform a request. Is there any better solution? I could not find any relevant methods in the API (I looked in package org.apache.http
, but it seems it is completely unaware of what type of connection should be used).
Upvotes: 0
Views: 1234
Reputation: 11027
Doing as proposed in the question is perfect should the application need to submit the HTTP request thru GSM now, at the time it is started or at the time the user triggers this action.
But if the app needs to do submit an HTTP request when the connection type is GSM that's a bit different. In that last case I would do that way:
private static boolean isOnlineUsingGsm(Context ctx) {
final ConnectivityManager connectManager = (ConnectivityManager)ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
// Return true if connected thru GSM
return connectManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED;
}
private void somewhereInTheCode() {
if (isOnlineUsingGsm(context)) {
sendHttpRequest();
}
// else don't send it
}
Upvotes: 1
Reputation: 14376
but it seems it is completely unaware of what type of connection should be used
correct - indirection is your friend - Location Services (for example) are just the same
Upvotes: 0