7

Google play does this when you try to use it and happen to not be connected to a wifi network.

photo of what I'm trying to do:

image

If you just run a standard

startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));

Then it loads up the window I'm looking for. However, I want a 'back' and 'next' button overlayed on top of it. Back should return to the previous window and next should only be selectable if a network has been selected and authentication is performed (if required). It would then go to another activity.

I tried implementing it with fragments (one for the intent launched window and another for the button), but it isn't working.

This was the code that launched when the app did

public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layfile);
//        Intent n = new Intent(this,Pactivity.class);
//        startActivity(n);
//        
    }
}

public class Pactivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    //addPreferencesFromIntent(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
    setContentView(R.layout.main);

}

}

public class Pfrag extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
    }
}

Here are the xml files

<?xml version="1.0" encoding="UTF-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >    
    <Preference 
        android:key="key"   
        android:title="WiFi" 
        android:summary="Calls WiFi">           
            <intent android:action="android.net.wifi.PICK_WIFI_NETWORK"/>           
    </Preference>
</PreferenceScreen>

I also tried some thrown together Preferences based classes. Also not doing what I want.

How can I get buttons overlayed on to what you see with a WifiManager.ACTION_PICK_WIFI_NETWORK?

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
Sojurn
  • 475
  • 6
  • 15
  • 1
    This is a programming question, more suitable for StackOverflow. This StackExchange is more about Android and maximising the user's usage of Android smartphones/tablets. – t0mm13b Jun 26 '12 at 20:03

2 Answers2

21
    Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);       
    intent.putExtra("only_access_points", true);
    intent.putExtra("extra_prefs_show_button_bar", true);
    intent.putExtra("wifi_enable_next_on_connect", true);
    startActivityForResult(intent, 1);

This should do it. Reverse engineered from google code.

UncleKing
  • 723
  • 4
  • 10
  • 1
    How do you get the picked network? the screen that opens with this intent doesn't offer a select option. it just lets you manage your connections. – Anonymous Feb 15 '14 at 00:31
  • 1
    Depending on what the user has chosen (back or next), you will get your result code. Realize that the user cannot select next till a wifi is selected. Once you get next you can enumerate the wificonnections and check which is connected wifiManager.getConfiguredNetworks(); - status – UncleKing Feb 15 '14 at 03:41
  • @uncleking is there a way to remove the back button? – Alexis Jun 28 '15 at 16:39
  • Any way to open Bluetooth settings like this wifi – Jigar Patel Jun 07 '19 at 11:45
3

This is just an improvement of UncleKing's answer.

Since you ask specifically for

How can I get buttons overlayed on to what you see with a WifiManager.ACTION_PICK_WIFI_NETWORK?

There is no need for the extras only_access_points and wifi_enable_next_on_connect. You only need the extra_prefs_show_button_bar extra. The overlay buttons will appear just by using this last extra.

You can try this using ADB if you want:

am start -a android.net.wifi.PICK_WIFI_NETWORK --ez extra_prefs_show_button_bar True

So the reduced code would be:

Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK);       
intent.putExtra("extra_prefs_show_button_bar", true);
startActivityForResult(intent, 1);

Tried it on Android 4.1, 4.4 and 5.1.

Storo
  • 988
  • 1
  • 7
  • 31