0

我一直在使用Wifimanager.updateNetwork(wifiConfiguration);在我的應用程序,它一直在Kitkat,果凍豆& ICS,但現在在棉花糖,它保持返回-1,即使當wifi配置不爲空,並有一個有效NETWORKID。有誰知道這可能的原因?棉花糖對此有所改變嗎?WifiManager.updateNetwork不能在棉花糖工作

回答

2

Android 6.0 Wi-Fi and Networking Changes

您的應用程序可以改變現在只有當你創建這些對象WifiConfiguration的狀態對象。您不得修改或刪除由用戶或其他應用創建的WifiConfiguration對象。

+0

有關如何使用新API實現WiFi優先級的任何想法? – CVA

+0

或如何禁用網絡,使系統不會自動重新連接到它?基本上你現在只能斷開連接,但這不會使系統不嘗試重新連接。所以是的,除非他們關閉網絡,否則應用幾乎不會斷開連接。 – leRobot

0
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;  


if(Build.VERSION.SDK_INT < 23){ 
    //your code here 
}else { 
    requestContactPermission(); 
} 



private void requestContactPermission() { 

int hasContactPermission =ActivityCompat.checkSelfPermission(context,Manifest.permission.ACCESS_WIFI_STATE); 

if(hasContactPermission != PackageManager.PERMISSION_GRANTED) { 
    ActivityCompat.requestPermissions(Context, new String[]{Manifest.permission.ACCESS_WIFI_STATE,Manifest.permission.ACCESS_WIFI_STATE}, PERMISSION_REQUEST_CODE); 
}else { 
    //Toast.makeText(AddContactsActivity.this, "Wifi Permission is already granted", Toast.LENGTH_LONG).show(); 
    } 
} 


@Override 
public void onRequestPermissionsResult(int requestCode, String[]  permissions, int[] grantResults) { 
switch (requestCode) { 
    case REQUEST_CODE_ASK_PERMISSIONS: 
     // Check if the only required permission has been granted 
     if (grantResults.length >0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

      Log.i("Permission", "Wifi permission has now been granted. Showing result."); 
      Toast.makeText(this," Wifi Permission is Granted",Toast.LENGTH_SHORT).show(); 
     } else { 
      Log.i("Permission", "Wifi permission was NOT granted."); 
      } 

     break; 

    } 
}