Open wireless settings from app

一世执手 提交于 2019-11-28 16:44:55

问题


I want to open the Settings-> Wireless & networks directly from my application.

How can I do that?


回答1:


Try this:

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));

Or perhaps startActivityForResult. Your call. You can open different settings by checking the constants in Settings




回答2:


You can access the WiFi settings directly using this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.wifi.WifiSettings");
startActivity(intent);

The above did not work on Android 3.0, so I ended up using:

Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
startActivity(intent);



回答3:


That code works for me.

startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));




回答4:


use the below code to call wireless and networks directly from your application.

Intent intent=new Intent();
            intent.setComponent(new ComponentName("com.android.settings", "com.android.settings.WirelessSettings"));
            startActivity(intent);



回答5:


Use Following Function For Open WI_FI Settings

private void openWifi() {
    Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
    startActivity(intent);
}



回答6:


i tried solutions above and it give me error that if you want to open external open you should flag that intent with FLAG_ACTIVITY_NEW_TASK
here is my solution in kotlin

val intent = Intent(Settings.ACTION_WIFI_SETTINGS)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(getApplication(), intent, null)


来源:https://stackoverflow.com/questions/7454416/open-wireless-settings-from-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!