简体   繁体   中英

Android: How to show wifi setting in pop up window

I have following code, which bring my app to the background and bring out the WIFI setting

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Is it possible to have the WIFI setting shown up in a alert dialog so it doesn't leave my app?

Thanks.

Create dialog like this :

final WifiManager mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);

        // set title
        alertDialogBuilder.setTitle("Wifi Settings");

        // set dialog message
        alertDialogBuilder
            .setMessage("Do you want to enable WIFI ?")
            .setCancelable(false)
            .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    //enable wifi
                    wifiMan.setWifiEnabled(true);
                }
              })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    //disable wifi
                    wifiMan.setWifiEnabled(false);
                }
            });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
            alertDialog.show();

Hope it will Help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM