Android Connectivity manager
I use the following statement
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Also this imports
import android.content.Context;
import android.net.ConnectivityMana开发者_StackOverflowger;
Ans this permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
But I get this error : The method getSystemService(String) is undefined for the type Network_Connectivity
getSystemService needs to be called from context or Activity class. Looks like ur Network_Connectivity doesnt extends Activity.
Pass context as a param and try something like this:
public void initConnectivityManager(Context c) {
Context c = context;
context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
精彩评论