开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜