java - 安卓工作室 : ActivityNotFoundException: Wi-Fi Settings

标签 java android

我正在尝试在 andoird 应用程序中以编程方式打开 wifi 设置。它适用于大多数设备,但在安卓平板电脑上它崩溃并给我这个错误:

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.settings/com.android.settings.wifi.WifiSettings}; have you declared this activity in your AndroidManifest.xml?

这是我在主要 Activity 中的代码:

Button wifisettings = (Button) findViewById(R.id.WiFiSettings);
    wifisettings.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            final Intent intent = new Intent(Intent.ACTION_MAIN, null);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
            intent.setComponent(cn);
            intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });

最佳答案

如果你想从你的应用程序调用 WiFiSettings 使用这个:

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

看看这个https://developer.android.com/reference/android/provider/Settings了解更多信息以及如何将用户带到那里

关于java - 安卓工作室 : ActivityNotFoundException: Wi-Fi Settings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52805722/

相关文章:

java - Android - 条件访问 Jar

java - 在 XML 节点中查找模式的最快(实现)方式

android - 安卓NDK的使用

java - 尝试在 android 中通过 JSONarray 验证密码

Java 和 gstreamer-java 初始化错误

java - 减少java中条形图的宽度

java - 从对象创建 Jackson ObjectNode

android - 使用抽屉导航中的 fragment 来叠加 Activity

android - 在 XML 中将 ActionBar 背景颜色设置为 colorPrimary 以外的颜色

单实例Activity的Android Fragment生命周期