Reputation: 41759
This app must not work without active Internet connection. But, checking Internet connection via ConnectivityManager
and NetworkInfo
does not work if firewall apps like DroidWall
have denied access to Internet (firewall rule).
How can I detect that some firewall app has blocked Internet access to my app?
For example, if I start Google Play Store app, it clearly states "No Internet connection". If I start my app, it hangs (trying to download content) and then crashes with an error.
EDIT
This is error caught by Logcat.
12-05 12:44:51.417: E/AndroidRuntime(18922): java.lang.RuntimeException: An error occured while executing doInBackground()
12-05 12:44:51.417: E/AndroidRuntime(18922): at android.os.AsyncTask$3.done(AsyncTask.java:278)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
12-05 12:44:51.417: E/AndroidRuntime(18922): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.lang.Thread.run(Thread.java:856)
12-05 12:44:51.417: E/AndroidRuntime(18922): Caused by: java.lang.NullPointerException
12-05 12:44:51.417: E/AndroidRuntime(18922): at com.app.android.MainActivity$ParserAsyncTask.doInBackground(MainActivity.java:345)
12-05 12:44:51.417: E/AndroidRuntime(18922): at com.app.android.MainActivity$ParserAsyncTask.doInBackground(MainActivity.java:367)
12-05 12:44:51.417: E/AndroidRuntime(18922): at android.os.AsyncTask$2.call(AsyncTask.java:264)
12-05 12:44:51.417: E/AndroidRuntime(18922): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
12-05 12:44:51.417: E/AndroidRuntime(18922): ... 5 more
As you see, the mechanism which detects whether Internet connection (wifi or mobile data) exists or not failed as the app was started and the parser started downloading remote content.
I need to implement additional feature which will allow Internet connection mechanism to check if some app is blocked by some firewall rule (like Play Store app does).
Upvotes: 1
Views: 8069
Reputation: 132
If your application is crashing then it's throwing an exception you are not catching.
Try to surround your connection code with try/catch and pop a toast notification
that there is no internet connection available in the catch. Also, post the exception from the debugging tools? I'm curious what exception you are getting since you haven't posted any code...
Upvotes: 1