Android Lollipop - WiFi Hotspot setWifiApEnabled() get InvocationTargetException

前端 未结 5 1854
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-10 11:12

I\'m using in the app

setWifiApEnabled()

from Hidden API (access by reflection). In some older phone it´s working (also with Samsung Galaxy S3,

5条回答
  •  鱼传尺愫
    2021-02-10 11:26

    public void setWiFiApMode(boolean mode) {
            if (mContext == null) return;
            WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
            if (wifiManager == null) return;
            try {
                Method setWifiApEnabled = WifiManager.class.getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
                setWifiApEnabled.invoke(wifiManager, null, mode);
            } catch (Exception e) {
            }
        }
    

    and

    
    
    

    Fully works on Android N.

提交回复
热议问题