Checking Device Has Internet Connection
I followed this Keep checking if Device has internet connection to check internet connectivity using BroadcastReceiver, the problem is how to call this registerReceiver(mConnRece
Solution 1:
Try this:
if(isNetworkStatusAvialable(getApplicationContext()))
{
}else
{
publicstaticbooleanisNetworkStatusAvialable(Context context) {
ConnectivityManagerconnectivityManager= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfonetInfos= connectivityManager.getActiveNetworkInfo();
if (netInfos != null)
if (netInfos.isConnected())
if (netInfos.isAvailable())
returntrue;
}
returnfalse;
}
Solution 2:
You have two options
1. in your MainActivity.java
// create object of receiver class NetworkChangeReceivermConnReceiver=newNetworkChangeReceiver();
//register the receiver
registerReceiver(mConnReceiver,newIntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
2. In manifest
file
<receiverandroid:name=".NetworkChangeReceiver" ><intent-filter><actionandroid:name="android.net.conn.CONNECTIVITY_CHANGE" /></intent-filter></receiver>
Post a Comment for "Checking Device Has Internet Connection"