你为什么不试试这个而不是比较版本名称尝试比较版本号
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));
}
并为结果使用以下事件
@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
}
}
}