I'm trying to test the internet connection of my app, and I'm testing it with "ConnectivityManager".
I'would like to call the ConnectivityManager class not from the main class, but from a class a made just to handel the connectivity test.
the method "getSystemService" in the second class gives me an error, how come???
This is the main class calling the connectivitymanager class:
public void onClick(View v){
Log.d("mytag", "in onclick");
CheckInternetpermission obCheckInternetPermission= new CheckInternetpermission();
Log.d("mytag", "starting permission");
obCheckInternetPermission.check();
}
This is the connectivitymanager, "getSystemService" gives me this error: Cannot resolve method 'getSystemService(java.lang.String)
package com.example.network;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.view.View;
public class CheckInternetpermission{
public void check(){
Log.d("mytag", "In check");
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE); //<---getSystemService give me error??????
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
Log.d("mytag", "Internet connection TRUE");
} else {
Log.d("mytag","Internet connection FALSE"); // display error
}
}
}