Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: ActivityNotFoundException: Wi-Fi Settings

Tags:

java

android

I'm trying to open open the wifi setting programmatically in an andoird app. It works on most devices, but on an android tablet it crashes and gives me this error:

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?

Here is my code in the main 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);
        }
    });
like image 610
A P Avatar asked Aug 31 '25 18:08

A P


1 Answers

If you want to call WiFiSettings from your app use this:

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Look into this https://developer.android.com/reference/android/provider/Settings for further sttings and how to take the user there

like image 94
Jav T Avatar answered Sep 02 '25 08:09

Jav T