mobile: prevent force close in onStop() method on devices without mobile

data connection module
This commit is contained in:
Philipp Schaefer 2013-04-10 14:56:50 +02:00
parent 0d51e045a0
commit 886c56da94
3 changed files with 24 additions and 13 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cradle.iitc_mobile"
android:versionCode="7"
android:versionName="0.2.6" >
android:versionCode="8"
android:versionName="0.2.7" >
<uses-sdk
android:minSdkVersion="14"

View File

@ -14,7 +14,7 @@
<string name="about">About</string>
<string name="pref_about_title">About IITC Mobile</string>
<!-- Use CDATA to prevent android from parsin html tags....we are doing this with Html.fromHtml() -->
<!-- Use CDATA to prevent android from parsing html tags....we are doing this with Html.fromHtml() -->
<string name="pref_about_msg">
<![CDATA[<big><b>Ingress Intel Total Conversion Mobile</b></big><br><br>
<b>by <a href="https://github.com/leCradle">cradle</a></b><br><br>

View File

@ -6,7 +6,6 @@ import com.cradle.iitc_mobile.R;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
@ -85,17 +84,29 @@ public class IITC_Mobile extends Activity {
protected void onStop() {
ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
State mobile = conMan.getNetworkInfo(0).getState();
State wifi = conMan.getNetworkInfo(1).getState();
NetworkInfo mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
// check if Mobile or Wifi module is available..then handle states
// TODO: theory...we do not have to check for a Wifi module...every android device should have one
if (mobile != null) {
Log.d("iitcm", "mobile internet module detected...check states");
if (mobile.getState() == NetworkInfo.State.CONNECTED || mobile.getState() == NetworkInfo.State.CONNECTING) {
Log.d("iitcm", "connected to mobile net...abort all running requests");
// cancel all current requests
iitc_view.loadUrl("javascript: window.requests.abort()");
// set idletime to maximum...no need for more
iitc_view.loadUrl("javascript: window.idleTime = 999");
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
} else if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) {
iitc_view.loadUrl("javascript: window.idleTime = 999");
}
} else {
Log.d("iitcm", "no mobile internet module detected...check wifi state");
if (wifi.getState() == NetworkInfo.State.CONNECTED || wifi.getState() == NetworkInfo.State.CONNECTING) {
iitc_view.loadUrl("javascript: window.idleTime = 999");
}
}
Log.d("iitcm", "stopping iitcm");
super.onStop();
}