开发者

Android Connectivity manager

开发者 https://www.devze.com 2023-04-12 17:27 出处:网络
I use the following statement ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消