android.net.WifiManager无法解析为变量 [英] android.net.WifiManager cannot be resolved to a variable
本文介绍了android.net.WifiManager无法解析为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的MainActivity中有此类,用于检测Internet连接和wifi扫描结果。我马上就收到以下错误消息: android.net.wifi.SCAN_RESULTS无法解析为类型
I have this class in my MainActivity to detect Internet Connection and wifi scanning result. I am getting at the Moment this error "android.net.wifi.SCAN_RESULTS cannot be resolved to a type" at this
内部MainActivity:
inner MainActivity:
class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(
android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
} else if(intent.getAction().equals(android.net.WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { //here is the error
}
}
}
<receiver android:name=".ConnectionBroadcast" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.SCAN_RESULTS" />
</intent-filter>
</receiver>
推荐答案
只需尝试以下最适合我的方法:
Just try this The best that worked for me:
AndroidManifest
<receiver android:name="com.AEDesign.communication.WifiReceiver" >
<intent-filter android:priority="100">
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
BroadcastReceiver类
public class WifiReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if(info != null) {
if(info.isConnected()) {
// Do your work.
// e.g. To check the Network Name or other info:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
}
}
}
}
权限
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
这篇关于android.net.WifiManager无法解析为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文