我不想自动启用android热点。
但是我得到了错误
Target SDK: 26
D/WifiManager: LocalOnlyHotspotCallbackProxy: handle message what: 2 msg: { when=-41ms what=2 arg1=3 target=android.net.wifi.WifiManager$LocalOnlyHotspotCallbackProxy$1 }
W/WifiManager: LocalOnlyHotspotCallbackProxy: failed to start. reason: 3
D/ApManager_Oreo: onFailed:
W/WifiManager: done with the callback...
我的代码来自Stackoverflow
How to turn on/off wifi hotspot programmatically in Android 8.0 (Oreo)
@RequiresApi(api = Build.VERSION_CODES.O)
public void turnOnHotspot() {
WifiManager manager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
manager.startLocalOnlyHotspot(new WifiManager.LocalOnlyHotspotCallback() {
@Override
public void onStarted(WifiManager.LocalOnlyHotspotReservation reservation) {
super.onStarted(reservation);
Log.d(TAG, "Wifi Hotspot is on now");
mReservation = reservation;
}
@Override
public void onStopped() {
super.onStopped();
Log.d(TAG, "onStopped: ");
}
@Override
public void onFailed(int reason) {
super.onFailed(reason);
Log.d(TAG, "onFailed: ");
}
}, new Handler());
}
已授予权限。我只在LG设备上出现此错误。三星和诺基亚运作良好。