Java Class
public class NetworkStatus extends BroadcastReceiver{
public static boolean isConnected;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if(isConnected)
{
Toast.makeText(context, "Internet Connection Lost", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context, "Internet Connected", Toast.LENGTH_LONG).show();
// new RequestService(context);
}
}
}
ManiFest XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditmicrosys.easylife"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.aditmicrosys.easylife.Splash_Screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.aditmicrosys.comman.NetworkStatus" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
</application>
public class NetworkStatus extends BroadcastReceiver{
public static boolean isConnected;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if(isConnected)
{
Toast.makeText(context, "Internet Connection Lost", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context, "Internet Connected", Toast.LENGTH_LONG).show();
// new RequestService(context);
}
}
}
ManiFest XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.aditmicrosys.easylife"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/appicon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.aditmicrosys.easylife.Splash_Screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.aditmicrosys.comman.NetworkStatus" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
No comments:
Post a Comment