我在logcat中遇到错误,如getNetworkInfo,wifi_p2p_statetracker

时间:2016-02-25 09:23:15

标签: java android

Error in Logcat
下面是我的网络连接代码,我得到" Wifi_P2p_StateTracker"错误,如何解决此错误,在AndroidManifest文件中我已声明所有权限。

public class ConnectionDetector {

    private Context context;

    public ConnectionDetector(Context context) {
        this.context = context;
    }

    public boolean isConnected() {

        boolean wifiDataAvailable = false;
        boolean mobileDataAvailable = false;
        try {
            ConnectivityManager conManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo[] networkInfo = conManager.getAllNetworkInfo();
            for (NetworkInfo netInfo : networkInfo) {

                if (netInfo.getTypeName().equalsIgnoreCase("WIFI"))
                    if (netInfo.isConnected())
                        wifiDataAvailable = true;

                if (netInfo.getTypeName().equalsIgnoreCase("MOBILE"))
                    if (netInfo.isConnected())
                        mobileDataAvailable = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wifiDataAvailable || mobileDataAvailable;
    }

}

0 个答案:

没有答案