相关疑难解决方法(0)

如何在Android 8.0(Oreo)中以编程方式打开/关闭wifi热点

我知道如何使用以下方法在android中使用反射打开/关闭wifi热点.

private static boolean changeWifiHotspotState(Context context,boolean enable) {
        try {
            WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
            Method method = manager.getClass().getDeclaredMethod("setWifiApEnabled", WifiConfiguration.class,
                    Boolean.TYPE);
            method.setAccessible(true);
            WifiConfiguration configuration = enable ? getWifiApConfiguration(manager) : null;
            boolean isSuccess = (Boolean) method.invoke(manager, configuration, enable);
            return isSuccess;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

但上面的方法不适用于Android 8.0(Oreo).

当我在Android 8.0中执行上面的方法时,我在logcat中得到以下语句.

com.gck.dummy W/WifiManager: com.gck.dummy attempted call to setWifiApEnabled: enabled = true
Run Code Online (Sandbox Code Playgroud)

在Android 8.0上有没有其他方法来开/关热点

android android-wifi hotspot android-8.0-oreo

17
推荐指数
2
解决办法
2万
查看次数

标签 统计

android ×1

android-8.0-oreo ×1

android-wifi ×1

hotspot ×1