0

I want to be able to open Android's stock Wifi Settings screen from my app, got this code:

Intent settings = new Intent(Settings.ACTION_WIFI_SETTINGS);
settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(settings);

I get "Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@45a3df40"

If I'm correct I need to declare the activity in my manifest.. but HOW? I've tried this:

<activity android:name="android.settings.WIFI_SETTINGS" />

Or am I doing something else wrong??

UPDATE: I was trying to access the Wifi Settings Activity from an PreferenceActivity's onOptionsItemSelected method. This DOES NOT WORK for either startActivity, startService OR sendBroadcast.

The answer below DOES work in pretty much every other scenario.. :)

REJH
  • 2,971
  • 4
  • 26
  • 50
  • And duplicate of http://stackoverflow.com/questions/2318310/how-can-i-call-wi-fi-settings-screen-from-my-application-using-android – Snicolas Jun 02 '11 at 12:48

1 Answers1

0

You only have to declare your activities in your manifest. Not the one that belong to external programs.

And remove the flags in your intent, I can't see the point for them.

startActivity( new Intent(android.provider.settings.Settings.ACTION_WIFI_SE‌​TTINGS) );
Snicolas
  • 36,854
  • 14
  • 106
  • 172
  • Okay this is really stupid but apparently it just won't work when it's called from a PreferenceActivity.. I've tried your code in my main activity and it worked straight away. Pff. Will try to bypass this by using a broadcastreceiver but I think the problem is the context (which is just passed to the receiver if I do it like this) – REJH Jun 02 '11 at 13:04
  • Okay I just can't start ANYTHING from an optionsmenu in a preferenceActivity... No broadcast, no service, no activity. SO LAME :( – REJH Jun 02 '11 at 13:25