我有一台三星 Galaxy S7 设备,我正在尝试使用它来访问 wifi 信息。我试图在运行时从片段请求权限,但弹出窗口不显示。
这是我正在尝试做的代码
private static final int PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION = 1001;
private void requestPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
getActivity().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(getActivity(),new String[]{Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.CHANGE_WIFI_STATE},
PERMISSIONS_REQUEST_CODE_ACCESS_COARSE_LOCATION );
}
}
您不能在片段中请求权限吗?这必须在活动中完成吗?