1

How do you prompt the user to turn on WiFi? I understand how to force WiFi to be turned on, as in this example, but my goal is to have the user be able to choose.

I have search the WiFiManager class and other similar classes with no luck. Thanks in advance!

Example of my goal, as done in Bluetooth

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
Community
  • 1
  • 1
Daiwik Daarun
  • 3,804
  • 7
  • 33
  • 60

1 Answers1

0

Hmm.. Why not Create a alert box with two buttons? Based on what the user chooses you could either enable or do nothing with the WIFI.

Like this

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Do you want to turn WIFI ON?")
       .setCancelable(false)
       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
       public void onClick(DialogInterface dialog, int id) {
       WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
       wifi.setWifiEnabled(true); // true or false to activate/deactivate wifi
           }
       })
       .setNegativeButton("No", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                // Do Nothing or Whatever you want.
                dialog.cancel();
           }
       });
    AlertDialog alert = builder.create();
    alert.show();

Hope that helps. My goal here was to replicate the Bluetooth alert box somewhat.

SeahawksRdaBest
  • 868
  • 5
  • 17