I'm very beginner in android , i write this class for check the network connection:
public class ConnectivityDetector {
public static boolean IS_INTERNET_AVAILABLE(Context context){
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED)
{
return true;
}
}
return false;
}
}
and with this code i want call that class:
public class AlarmReciever extends BroadcastReceiver {
Context context;
@Override
public void onReceive(Context context, Intent intent) {
if (ConnectivityDetector.IS_INTERNET_AVAILABLE(AlarmReciever.this)) {
//write my code
}
}
}
but in this line:
if (ConnectivityDetector.IS_INTERNET_AVAILABLE(AlarmReciever.this))
i get this error:

how can i solve that?
AlarmReciever is not context, so you can't use this. You have the parameter Context context in on receive. You could use that one.
public class AlarmReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (ConnectivityDetector.IS_INTERNET_AVAILABLE(context)) {
//write my code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With