添加应用程序名称以请求扫描始终可用(三星)

Add app name to request scan always available (Samsung)

我使用以下代码,要求用户启用扫描始终可用

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN_MR2 && !wifiManager.isScanAlwaysAvailable)
        startActivity(Intent(ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE))

它可以正常工作,但在 Samsung Galaxy Note 4 上 window 中的文本显示为 "null requests permission"


截图:

如何将null替换为应用名称?

你为什么不试试这个而不是比较版本名称尝试比较版本号

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
         }
     }
}