Android 11 wifiInfo.getSSID 获取不到WiFi名称

android 高版本获取WiFi名称需要授予位置权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

获取权限代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQ_CODE_FINE_LOCATION);
}
}

获取权限回调
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQ_CODE_FINE_LOCATION:
if (grantResults.length > 0 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
TMLUtils.showTips(this, getString(R.string.req_location_tips));
}
break;
}
}
posted @ 2023-08-08 14:55  Jokeyyu  阅读(399)  评论(0编辑  收藏  举报