After a long period of inactivity within my app, all the get requests
start failing with a connection timeout error. I notice this was
happening when the phone is connected over the 3G network, and not
when it is connected to wifi.. At present to get it to work, i toggle
the airplane mode state twice and the network connections get reset.Is
this the best way to go about doing this ? Please enlighten!
void toggleAirplaneMode(){
//Toggling airplane mode to restart network
Context context = getApplicationContext();
boolean isEnabled = Settings.System.getInt(
context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
// toggle airplane mode
Settings.System.putInt(
context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
// Post an intent to reload
Intent intent = new
Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
context.sendBroadcast(intent);
Log.d("Inetify", "Toggling Airplane Mode");
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en