Example usage for android.provider Settings ACTION_WIFI_SETTINGS

List of usage examples for android.provider Settings ACTION_WIFI_SETTINGS

Introduction

In this page you can find the example usage for android.provider Settings ACTION_WIFI_SETTINGS.

Prototype

String ACTION_WIFI_SETTINGS

To view the source code for android.provider Settings ACTION_WIFI_SETTINGS.

Click Source Link

Document

Activity Action: Show settings to allow configuration of Wi-Fi.

Usage

From source file:com.phonegap.plugins.nativesettings.NativeSettings.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult.Status status = PluginResult.Status.OK;
    Uri packageUri = Uri.parse("package:" + this.cordova.getActivity().getPackageName());
    String result = "";

    //Information on settings can be found here:
    //http://developer.android.com/reference/android/provider/Settings.html

    action = args.getString(0);//  w  w w .  j  av  a 2s. co m
    Intent intent = null;

    if (action.equals("accessibility")) {
        intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
    } else if (action.equals("account")) {
        intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
    } else if (action.equals("airplane_mode")) {
        intent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS);
    } else if (action.equals("apn")) {
        intent = new Intent(android.provider.Settings.ACTION_APN_SETTINGS);
    } else if (action.equals("application_details")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageUri);
    } else if (action.equals("application_development")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
    } else if (action.equals("application")) {
        intent = new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS);
    }
    //else if (action.equals("battery_saver")) {
    //    intent = new Intent(android.provider.Settings.ACTION_BATTERY_SAVER_SETTINGS);
    //}
    else if (action.equals("bluetooth")) {
        intent = new Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS);
    } else if (action.equals("captioning")) {
        intent = new Intent(android.provider.Settings.ACTION_CAPTIONING_SETTINGS);
    } else if (action.equals("cast")) {
        intent = new Intent(android.provider.Settings.ACTION_CAST_SETTINGS);
    } else if (action.equals("data_roaming")) {
        intent = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS);
    } else if (action.equals("date")) {
        intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
    } else if (action.equals("about")) {
        intent = new Intent(android.provider.Settings.ACTION_DEVICE_INFO_SETTINGS);
    } else if (action.equals("display")) {
        intent = new Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS);
    } else if (action.equals("dream")) {
        intent = new Intent(android.provider.Settings.ACTION_DREAM_SETTINGS);
    } else if (action.equals("home")) {
        intent = new Intent(android.provider.Settings.ACTION_HOME_SETTINGS);
    } else if (action.equals("keyboard")) {
        intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS);
    } else if (action.equals("keyboard_subtype")) {
        intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
    } else if (action.equals("storage")) {
        intent = new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS);
    } else if (action.equals("locale")) {
        intent = new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS);
    } else if (action.equals("location")) {
        intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    } else if (action.equals("manage_all_applications")) {
        intent = new Intent(android.provider.Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    } else if (action.equals("manage_applications")) {
        intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
    } else if (action.equals("memory_card")) {
        intent = new Intent(android.provider.Settings.ACTION_MEMORY_CARD_SETTINGS);
    } else if (action.equals("network")) {
        intent = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS);
    } else if (action.equals("nfcsharing")) {
        intent = new Intent(android.provider.Settings.ACTION_NFCSHARING_SETTINGS);
    } else if (action.equals("nfc_payment")) {
        intent = new Intent(android.provider.Settings.ACTION_NFC_PAYMENT_SETTINGS);
    } else if (action.equals("nfc_settings")) {
        intent = new Intent(android.provider.Settings.ACTION_NFC_SETTINGS);
    }
    //else if (action.equals("notification_listner")) {
    //    intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
    //}
    else if (action.equals("print")) {
        intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
    } else if (action.equals("privacy")) {
        intent = new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
    } else if (action.equals("quick_launch")) {
        intent = new Intent(android.provider.Settings.ACTION_QUICK_LAUNCH_SETTINGS);
    } else if (action.equals("search")) {
        intent = new Intent(android.provider.Settings.ACTION_SEARCH_SETTINGS);
    } else if (action.equals("security")) {
        intent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
    } else if (action.equals("settings")) {
        intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
    } else if (action.equals("show_regulatory_info")) {
        intent = new Intent(android.provider.Settings.ACTION_SHOW_REGULATORY_INFO);
    } else if (action.equals("sound")) {
        intent = new Intent(android.provider.Settings.ACTION_SOUND_SETTINGS);
    } else if (action.equals("store")) {
        intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("market://details?id=" + this.cordova.getActivity().getPackageName()));
    } else if (action.equals("sync")) {
        intent = new Intent(android.provider.Settings.ACTION_SYNC_SETTINGS);
    } else if (action.equals("usage")) {
        intent = new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS);
    } else if (action.equals("user_dictionary")) {
        intent = new Intent(android.provider.Settings.ACTION_USER_DICTIONARY_SETTINGS);
    } else if (action.equals("voice_input")) {
        intent = new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS);
    } else if (action.equals("wifi_ip")) {
        intent = new Intent(android.provider.Settings.ACTION_WIFI_IP_SETTINGS);
    } else if (action.equals("wifi")) {
        intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
    } else if (action.equals("wireless")) {
        intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
    } else {
        status = PluginResult.Status.INVALID_ACTION;
        callbackContext.sendPluginResult(new PluginResult(status, result));
        return false;
    }

    if (args.length() > 1 && args.getBoolean(1)) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    this.cordova.getActivity().startActivity(intent);

    callbackContext.sendPluginResult(new PluginResult(status, result));
    return true;
}

From source file:com.nest5.businessClient.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*  ww  w.  ja  va 2  s.  com*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }

    // internetConnectionStatus = (ImageView) findViewById(R.id.header_connection_status);
    SharedPreferences prefs = Util.getSharedPreferences(mContext);
    if (!isNetworkAvailable()) {
        internetConnectionStatus.setImageResource(R.drawable.error);

        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_DISCONNECTED).commit();
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "No tienes una conexin a internet activa. Habiltala haciendo click en aceptar y seleccionando luego una red.")
                .setCancelable(false).setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
                        startActivityForResult(intent, 1);
                    }
                }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();

    } else {
        prefs.edit().putInt(Util.INTERNET_CONNECTION, Util.INTERNET_CONNECTED).commit();
    }
}

From source file:com.raza.betternts.activities.MainActivity.java

private void refresh() {
    if (isNetworkAvailable(MainActivity.this)) {
        doInBG();//from  w w w.  j  av a  2  s.  com
    } else if (isDBEmpty()) {
        new AlertDialog.Builder(MainActivity.this).setTitle("Error!")
                .setMessage("No internet\nCheck your network settings and try again.")
                .setPositiveButton("Settings", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                    }
                }).setCancelable(false).show();
    } else {
        showSnackBar("No Internet Connection", MainActivity.this);
    }
}

From source file:com.nks.nksmod.otaupdater.OTAUpdaterActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final Context context = getApplicationContext();
    cfg = Config.getInstance(context);/*from  ww w  .  j a  va2  s  .  com*/
    final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 0;

    if (ContextCompat.checkSelfPermission(OTAUpdaterActivity.this,
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.alert_permission_storage);
            builder.setMessage(R.string.alert_permission_storage_message);
            builder.setCancelable(false);
            builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            builder.setNeutralButton(R.string.enable_permission, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    ActivityCompat.requestPermissions(OTAUpdaterActivity.this,
                            new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                            MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                }
            });

            final AlertDialog dlg = builder.create();

            dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialog) {
                    onDialogShown(dlg);
                }
            });
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    onDialogClosed(dlg);
                }
            });
            dlg.show();

        } else {
            ActivityCompat.requestPermissions(OTAUpdaterActivity.this,
                    new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

            if (ActivityCompat.shouldShowRequestPermissionRationale(OTAUpdaterActivity.this,
                    android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle(R.string.alert_permission_storage);
                builder.setMessage(R.string.alert_permission_storage_message);
                builder.setCancelable(false);
                builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                });

                final AlertDialog dlg = builder.create();

                dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                    @Override
                    public void onShow(DialogInterface dialog) {
                        onDialogShown(dlg);
                    }
                });
                dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialog) {
                        onDialogClosed(dlg);
                    }
                });
                dlg.show();

            }
        }
    }

    boolean data = Utils.dataAvailable(this);
    boolean wifi = Utils.wifiConnected(this);

    if (!data || !wifi) {
        final boolean nodata = !data && !wifi;

        if ((nodata && !cfg.getIgnoredDataWarn()) || (!nodata && !cfg.getIgnoredWifiWarn())) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(nodata ? R.string.alert_nodata_title : R.string.alert_nowifi_title);
            builder.setMessage(nodata ? R.string.alert_nodata_message : R.string.alert_nowifi_message);
            builder.setCancelable(false);
            builder.setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    finish();
                }
            });
            builder.setNeutralButton(R.string.alert_wifi_settings, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    Intent i = new Intent(Settings.ACTION_WIFI_SETTINGS);
                    startActivity(i);
                }
            });
            builder.setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (nodata) {
                        cfg.setIgnoredDataWarn(true);
                    } else {
                        cfg.setIgnoredWifiWarn(true);
                    }
                    dialog.dismiss();
                }
            });

            final AlertDialog dlg = builder.create();

            dlg.setOnShowListener(new DialogInterface.OnShowListener() {
                @Override
                public void onShow(DialogInterface dialog) {
                    onDialogShown(dlg);
                }
            });
            dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
                    onDialogClosed(dlg);
                }
            });
            dlg.show();
        }
    }

    Utils.updateDeviceRegistration(this);
    CheckinReceiver.setDailyAlarm(this);

    setContentView(R.layout.main);
    ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);

    bar = getActionBar();
    assert bar != null;

    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
    bar.setTitle(R.string.app_name);

    TabsAdapter mTabsAdapter = new TabsAdapter(this, mViewPager);
    mTabsAdapter.addTab(bar.newTab().setText(R.string.main_about), AboutTab.class);

    ActionBar.Tab romTab = bar.newTab().setText(R.string.main_rom);
    if (cfg.hasStoredRomUpdate())
        romTab.setIcon(R.drawable.ic_action_warning);
    romTabIdx = mTabsAdapter.addTab(romTab, ROMTab.class);

    /* ActionBar.Tab kernelTab = bar.newTab().setText(R.string.main_kernel);
    if (cfg.hasStoredKernelUpdate()) kernelTab.setIcon(R.drawable.ic_action_warning);
    kernelTabIdx = mTabsAdapter.addTab(kernelTab, KernelTab.class); */

    if (!handleNotifAction(getIntent())) {
        if (cfg.hasStoredRomUpdate() && !cfg.isDownloadingRom()) {
            cfg.getStoredRomUpdate().showUpdateNotif(this);
        }

        /* if (cfg.hasStoredKernelUpdate() && !cfg.isDownloadingKernel()) {
        cfg.getStoredKernelUpdate().showUpdateNotif(this);
        } */

        if (savedInstanceState != null) {
            bar.setSelectedNavigationItem(savedInstanceState.getInt(KEY_TAB, 0));
        }
    }
}

From source file:info.wncwaterfalls.app.AppInfoSettingsFragment.java

public void initializeDownloadUI(View view) {
    mPB = (ProgressBar) view.findViewById(R.id.progressBar);
    mGooglePlayServicesStatusText = (TextView) view.findViewById(R.id.googlePlayServicesStatusText);
    mExpansionDownloadStatusText = (TextView) view.findViewById(R.id.expansionDownloadStatusText);
    mProgressFraction = (TextView) view.findViewById(R.id.progressAsFraction);
    mProgressPercent = (TextView) view.findViewById(R.id.progressAsPercentage);
    mAverageSpeed = (TextView) view.findViewById(R.id.progressAverageSpeed);
    mTimeRemaining = (TextView) view.findViewById(R.id.progressTimeRemaining);
    mDashboard = view.findViewById(R.id.downloaderDashboard);
    mCellMessage = view.findViewById(R.id.approveCellular);
    mPauseButton = (Button) view.findViewById(R.id.pauseButton);
    mWiFiSettingsButton = (Button) view.findViewById(R.id.wifiSettingsButton);
    mClearMBTilesCacheButton = (Button) view.findViewById(R.id.clearCachedMBTilesButton);

    mClearMBTilesCacheButton.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w w . j  a  va2 s .c  o m
        public void onClick(View view) {
            clearCachedMBTilesFiles();
        }
    });

    mPauseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mStatePaused) {
                sExpansionFilesDownloadListener.serviceRequestContinueDownload();
            } else {
                sExpansionFilesDownloadListener.serviceRequestPauseDownload();
            }
            setButtonPausedState(!mStatePaused);
        }
    });
    setButtonPausedState(mStatePaused); // Set text

    mWiFiSettingsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
        }
    });

    Button resumeOnCell = (Button) view.findViewById(R.id.resumeOverCellular);
    resumeOnCell.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            sExpansionFilesDownloadListener
                    .serviceRequestSetDownloadFlags(IDownloaderService.FLAGS_DOWNLOAD_OVER_CELLULAR);
            sExpansionFilesDownloadListener.serviceRequestContinueDownload();
            mCellMessage.setVisibility(View.GONE);
        }
    });
}

From source file:com.google.android.gms.samples.vision.face.facetracker.MainActivity.java

void checkWifi(final WifiManager wifiManager) {
    Log.d("WIFI CHECK", wifiManager.getConnectionInfo().toString());

    //        Memeriksa jika wifi yang terkoneksi merupakan wifi yang diinginkan
    //        atau bukan
    if (wifiManager.getConnectionInfo().getBSSID() == null
            || wifiManager.getConnectionInfo().getBSSID().toString().compareTo(TARGET_WIFI_BSSID) != 0) {
        //            Menampilkan sebuah alert dialog yang meminta user untuk melakukan koneksi ke wifi
        //            dengan ssid yang diinginkan
        new AlertDialog.Builder(this)
                .setMessage("Please Connect to wifi network named '" + TARGET_WIFI_SSID + "'")
                .setPositiveButton("Connect to wifi", new DialogInterface.OnClickListener() {
                    @Override//from w  w  w  . j a  v a 2 s.c  om
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                        //                            User dialihkan ke setting wifi untuk melakukan koneksi ke wifi tujuan
                        startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                    }
                }).setNegativeButton("EXIT", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        finish();
                    }
                }).setCancelable(false).show();
        return;
    }
}

From source file:com.example.angelina.travelapp.places.PlacesActivity.java

private void checkSettings() {
    // Is GPS enabled?
    final boolean gpsEnabled = locationTrackingEnabled();
    // Is there internet connectivity?
    final boolean internetConnected = internetConnectivity();

    if (gpsEnabled && internetConnected) {
        completeSetUp();/*from  w  ww  . j a  v a  2s . co m*/
    } else if (!gpsEnabled) {
        final Intent gpsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        showDialog(gpsIntent, REQUEST_LOCATION_SETTINGS, getString(R.string.location_tracking_off));
    } else if (!internetConnected) {
        final Intent internetIntent = new Intent(Settings.ACTION_WIFI_SETTINGS);
        showDialog(internetIntent, REQUEST_WIFI_SETTINGS, getString(R.string.wireless_off));
    }
}

From source file:de.j4velin.wifiAutoOff.Preferences.java

@SuppressWarnings("deprecation")
@Override/*from   w ww.j  ava2  s .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);

    if (BuildConfig.DEBUG && PermissionChecker.checkSelfPermission(this,
            Manifest.permission.WRITE_EXTERNAL_STORAGE) != PermissionChecker.PERMISSION_GRANTED) {
        requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
    }

    status = (StatusPreference) findPreference("status");
    status.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(final Preference preference) {
            WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            boolean connected = ((ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE))
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
            if (wm.isWifiEnabled() && !connected) {
                try {
                    startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show();
                }
            } else if (!wm.isWifiEnabled()) {
                wm.setWifiEnabled(true);
            } else {
                try {
                    startActivity(
                            new Intent(Settings.ACTION_WIFI_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                } catch (Exception e) {
                    Toast.makeText(Preferences.this, R.string.settings_not_found_, Toast.LENGTH_SHORT).show();
                }
            }
            return true;
        }
    });

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    final CheckBoxPreference screen_off = (CheckBoxPreference) findPreference("off_screen_off");
    screen_off.setSummary(
            getString(R.string.for_at_least, prefs.getInt("screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF)));

    if (!keepWiFiOn(this)) {
        screen_off.setChecked(false);
    }

    screen_off.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((Boolean) newValue) {
                if (!keepWiFiOn(Preferences.this)) {
                    new AlertDialog.Builder(Preferences.this).setMessage(R.string.sleep_policy)
                            .setPositiveButton(R.string.adv_wifi_settings, new OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    try {
                                        startActivity(new Intent(Settings.ACTION_WIFI_IP_SETTINGS)
                                                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                                    } catch (Exception e) {
                                        Toast.makeText(Preferences.this, R.string.settings_not_found_,
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }).setNegativeButton(android.R.string.cancel, new OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create().show();
                    return false;
                }
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, screen_off,
                            R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_),
                            "screen_off_timeout", Receiver.TIMEOUT_SCREEN_OFF, false);
                } else {
                    showPre11NumberPicker(Preferences.this, prefs, screen_off, R.string.for_at_least, 1, 60,
                            getString(R.string.minutes_before_turning_off_wifi_), "screen_off_timeout",
                            Receiver.TIMEOUT_SCREEN_OFF, false);
                }
            }
            return true;
        }
    });

    findPreference("off_no_network").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((Boolean) newValue) {
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    APILevel11Wrapper.showNumberPicker(Preferences.this, prefs, preference,
                            R.string.for_at_least, 1, 60, getString(R.string.minutes_before_turning_off_wifi_),
                            "no_network_timeout", Receiver.TIMEOUT_NO_NETWORK, false);
                } else {
                    showPre11NumberPicker(Preferences.this, prefs, preference, R.string.for_at_least, 1, 60,
                            getString(R.string.minutes_before_turning_off_wifi_), "no_network_timeout",
                            Receiver.TIMEOUT_NO_NETWORK, false);
                }
            }
            return true;
        }
    });

    final CheckBoxPreference on_at = (CheckBoxPreference) findPreference("on_at");
    on_at.setTitle(getString(R.string.at_summary, prefs.getString("on_at_time", Receiver.ON_AT_TIME)));
    on_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((Boolean) newValue) {
                String[] time = prefs.getString("on_at_time", Receiver.ON_AT_TIME).split(":");
                final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        prefs.edit().putString("on_at_time",
                                hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit();
                        on_at.setTitle(getString(R.string.at_summary,
                                hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)));
                    }
                }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true);
                dialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        on_at.setChecked(false);
                    }
                });
                dialog.setTitle(getString(R.string.turn_wifi_on_at_));
                dialog.show();
            }
            return true;
        }
    });

    final CheckBoxPreference off_at = (CheckBoxPreference) findPreference("off_at");
    off_at.setTitle(getString(R.string.at_summary, prefs.getString("off_at_time", Receiver.OFF_AT_TIME)));
    off_at.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((Boolean) newValue) {
                String[] time = prefs.getString("off_at_time", Receiver.OFF_AT_TIME).split(":");
                final TimePickerDialog dialog = new TimePickerDialog(Preferences.this, new OnTimeSetListener() {
                    @Override
                    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                        prefs.edit().putString("off_at_time",
                                hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)).commit();
                        off_at.setTitle(getString(R.string.at_summary,
                                hourOfDay + ":" + (minute < 10 ? "0" + minute : minute)));
                    }
                }, Integer.parseInt(time[0]), Integer.parseInt(time[1]), true);
                dialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        off_at.setChecked(false);
                    }
                });
                dialog.setTitle(getString(R.string.turn_wifi_off_at_));
                dialog.show();
            }
            return true;
        }
    });

    final Preference on_every = findPreference("on_every");
    final String[] time_names = getResources().getStringArray(R.array.time_names);
    // default 2 hours
    on_every.setTitle(getString(R.string.every_summary, prefs.getString("on_every_str", time_names[4])));
    on_every.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((Boolean) newValue) {
                AlertDialog.Builder builder = new AlertDialog.Builder(Preferences.this);
                builder.setTitle(R.string.turn_wifi_on_every).setItems(time_names,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                prefs.edit().putInt("on_every_time_min", time_values[which])
                                        .putString("on_every_str", time_names[which]).commit();
                                on_every.setTitle(getString(R.string.every_summary, time_names[which]));
                            }
                        });
                builder.create().show();
            }
            return true;
        }
    });

    Preference locations = findPreference("locations");
    if (BuildConfig.FLAVOR.equals("play")) {
        if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK)) {
            locations.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(final Preference preference) {
                    startActivity(new Intent(Preferences.this, Locations.class));
                    return true;
                }
            });
        } else {
            locations.setEnabled(false);
        }
    } else {
        locations.setSummary("Not available in F-Droid version");
        locations.setEnabled(false);
    }

    final Preference power = findPreference("power_connected");
    power.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            if ((boolean) newValue) {
                Intent battery = registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
                if (battery != null && battery.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) > 0) {
                    // already connected to external power
                    prefs.edit().putBoolean("ignore_screen_off", true).commit();
                }
            } else {
                prefs.edit().putBoolean("ignore_screen_off", false).commit();
            }
            return true;
        }
    });
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

public boolean checkHardware(NfcAdapter mAdapter) {
    if (mAdapter == null) {
        Toast.makeText(this, getString(R.string.msg_error_nfc), Toast.LENGTH_LONG).show();
        finish();// www.  j  a v  a  2 s. co m
        return false;
    }

    if (!mAdapter.isEnabled()) {
        Toast.makeText(this, getString(R.string.msg_activ_nfc), Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
    }

    if (!isOnline()) {
        view.loadUrl("about:blank");
        Toast.makeText(this, getString(R.string.msg_activ_network), Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
    }
    return true;
}

From source file:net.yolosec.upckeygen.ui.NetworkFragment.java

/**
 * Try to open wifi settings activity.//  w w  w .  j  a  v  a 2  s.com
 * Tries to different actions.
 */
private void openWifiSettings() {
    Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
    final PackageManager packageManager = getActivity().getPackageManager();
    if (packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        startActivity(intent);
        return;
    }
    intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
    if (packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
        startActivity(intent);
    }
}