我使用以下代码,要求用户启用扫描始终可用
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR2 && !wifiManager.isScanAlwaysAvailable)
startActivity(Intent(ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE))
它的工作原理应该如此,但在三星Galaxy Note 4窗口中的文字显示为“空请求权限”
截图:
如何用应用名称替换null?
答案 0 :(得分:-2)
为什么不试试这个而不是比较版本名称尝试比较版本号
private static final int REQUEST_SCAN_ALWAYS_AVAILABLE = any_number;
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (Build.VERSION.SDK_INT >= 18 && !wifiManager.isScanAlwaysAvailable()) {
startActivityForResult(new Intent(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE, REQUEST_SCAN_ALWAYS_AVAILABLE));
}
并且在事件下面使用resutl
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == REQUEST_SCAN_ALWAYS_AVAILABLE)
{
// Make sure the request was successful
if (resultCode != RESULT_OK)
{
//User has not enabled the scan always available inform him to activate it
}
}
}