how to open configure portable Wi-Fi hotspot setting by onclick?

前端 未结 4 874
时光取名叫无心
时光取名叫无心 2020-12-19 16:51

how to open the following directory:settings/wireless and networks/Tethering and portable hotspot/portable Wi-Fi hotspot settings/configure portable Wi-Fi hotspot/ on butto

4条回答
  •  醉梦人生
    2020-12-19 17:15

    In case any one lands here like me, on Android 8, I used this to open up the setup Hotspot page itself.

    public static final String SETTINGS_PACKAGE = "com.android.settings";
    public static final String HOTSPOT_SETTINGS_CLASS = "com.android.settings.Settings$TetherWifiSettingsActivity";
    
    private void launchHotspotSettings(){
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        ComponentName componentName = new ComponentName(SETTINGS_PACKAGE, HOTSPOT_SETTINGS_CLASS);
        intent.setComponent(componentName);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    

    Works on my device. Let me know if it works on yours. After a bit of research I realized that this class changes per device brand. Eg. For Samsung, use

    public static final String HOTSPOT_SETTINGS_CLASS = "com.android.settings.Settings$WifiApSettingsActivity";
    

    By the way @Drew answer still works on Android 8.

提交回复
热议问题