android6.0以上開啟熱點失敗
最近在做手機移動端檔案傳輸app,該專案需要一端開啟熱點,另一端連線該熱點,從而兩個段之間建立區域網,進而通過socket通訊實現檔案傳輸功能,隨著測試的深入,發現,如果設定targetSdkversion >= 23的時候熱點建立失敗。百度了一下,全是許可權的問題,通過列印我的log,也提示是許可權問題,log如下:
08-18 13:12:01.907 21072-21794/? W/System.err: java.lang.reflect.InvocationTargetException
08-18 13:12:01.907 21072-21794/? W/System.err: at java.lang.reflect.Method.invoke(Native Method)
08-18 13:12:01.907 21072-21794/? W/System.err: at com.tpvtransfer.manager.WifiAPManager.setWifiApEnable(WifiAPManager.java:191)
08-18 13:12:01.907 21072-21794/? W/System.err: at com.tpvtransfer.sdk.SDKManager.createAp(SDKManager.java:66)
08-18 13:12:01.907 21072-21794/? W/System.err: at com.tpvtransfer.NewDeviceActivity.createAp(NewDeviceActivity.java:482)
08-18 13:12:01.908 21072-21794/? W/System.err: at com.tpvtransfer.NewDeviceActivity.access$23(NewDeviceActivity.java:480)
08-18 13:12:01.908 21072-21794/? W/System.err: at com.tpvtransfer.NewDeviceActivity$WorkingHandler.dispatchMessage(NewDeviceActivity.java:470)
08-18 13:12:01.908 21072-21794/? W/System.err: at android.os.Looper.loop(Looper.java:203)
08-18 13:12:01.908 21072-21794/? W/System.err: at android.os.HandlerThread.run(HandlerThread.java:61)
08-18 13:12:01.908 21072-21794/? W/System.err: Caused by: java.lang.SecurityException: com.tpv.transfer was not granted this permission: android.permission.WRITE_SETTINGS.
08-18 13:12:01.908 21072-21794/? W/System.err: at android.os.Parcel.readException(Parcel.java:1683)
08-18 13:12:01.908 21072-21794/? W/System.err: at android.os.Parcel.readException(Parcel.java:1636)
08-18 13:12:01.908 21072-21794/? W/System.err: at android.net.wifi.IWifiManager$Stub$Proxy.setWifiApEnabled(IWifiManager.java:1751)
08-18 13:12:01.909 21072-21794/? W/System.err: at android.net.wifi.WifiManager.setWifiApEnabled(WifiManager.java:1667)
好吧,但是我命名在menifest已經註冊了write_settings許可權了啊?
不然怎麼說自古網路出人才,http://blog.csdn.net/chengkaizone/article/details/53765934,然後選擇開啟,編譯安裝,正常開啟熱點,marks一下。