Issue
I'm trying to detect whether or not a user has internet connection on their android device. If they don't have internet, I want to be able to show a view that has a button on it that said "retry", like that of the Google Play app store. I was detecting no signal using a native android webview before using the code below, but I'd now like to find a way to do this same thing with PhoneGap. Also, if anybody could provide some sample code on how to re-load the webpage, that would be excellent!
webview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Intent myIntent = new Intent(view.getContext(), LoadScreen.class);
startActivity(myIntent);
finish();
}
});
Solution
Solved this by using the following code:
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}
Answered By - Mobie
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.