从应用程序打开无线设置

问题描述 投票:0回答:7

我想直接从我的应用程序打开“设置”->“无线和网络”。

我怎样才能做到这一点?

android settings wireless
7个回答
88
投票

试试这个:

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

或者也许是startActivityForResult。你的来电。 您可以通过检查Settings

中的常量来打开不同的设置

16
投票

您可以使用以下方法直接访问 WiFi 设置:

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

上面的方法在 Android 3.0 上不起作用,所以我最终使用了:

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

11
投票

该代码对我有用。

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


2
投票

使用以下代码直接从您的应用程序调用无线和网络。

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

1
投票

使用以下功能打开WI_FI设置

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

0
投票

我尝试了上面的解决方案,它给了我错误,如果你想打开外部打开,你应该用

FLAG_ACTIVITY_NEW_TASK
标记该意图
这是我的解决方案
kotlin

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

0
投票

这对我有用,2022 年的 kotlin。

 val context = LocalContext.current

 fun onEnableConnection() {
     startActivity(context, Intent(Settings.ACTION_WIFI_SETTINGS), null)   }
© www.soinside.com 2019 - 2024. All rights reserved.