我正在尝试在 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/