Sojurn
Sojurn

Reputation: 485

How can I overlay a 'back' and 'next' button on a " pick wifi network " window?

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?

Upvotes: 8

Views: 2740

Answers (2)

Storo
Storo

Reputation: 1008

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.

Upvotes: 3

UncleKing
UncleKing

Reputation: 743

    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.

Upvotes: 22

Related Questions