Example usage for android.provider Settings ACTION_SECURITY_SETTINGS

List of usage examples for android.provider Settings ACTION_SECURITY_SETTINGS

Introduction

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

Prototype

String ACTION_SECURITY_SETTINGS

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

Click Source Link

Document

Activity Action: Show settings to allow configuration of security and location privacy.

Usage

From source file:de.j4velin.encrypter.MainActivity.java

private void init() {
    Requirement error = getMissingRequirement();
    String exception = null;//ww  w .  j  a v  a  2s.c om
    if (error == null) {
        try {
            if (CipherUtil.init()) {
                new AlertDialog.Builder(this).setTitle(R.string.key_generated)
                        .setMessage(R.string.new_key_warning)
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(final DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                            }
                        }).create().show();
            }
        } catch (GeneralSecurityException | IOException e) {
            e.printStackTrace();
            exception = e.getMessage();
        }
    } else if (error.equals(Requirement.FINGERPRINT_PERMISSION)) {
        // ignore
        return;
    }
    if (error != null || exception != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (exception != null) {
            builder.setMessage(getString(R.string.error_load_key, exception));
        } else {
            switch (error) {
            case FINGERPRINT_SENSOR:
                builder.setMessage(R.string.error_no_fingerprint_hardware);
                break;
            case FINGERPRINT_SETUP:
                builder.setMessage(R.string.error_no_fingerprints);
                builder.setPositiveButton(R.string.register_finger, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialogInterface, int i) {
                        startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                        dialogInterface.cancel();
                    }
                });
                break;
            case DEVICE_SECURE:
                builder.setMessage(R.string.error_no_lockscreen);
                builder.setPositiveButton(R.string.setup_lockscreen, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialogInterface, int i) {
                        startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                        dialogInterface.cancel();
                    }
                });
                break;
            }
        }
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialogInterface, int i) {
                dialogInterface.cancel();
            }
        }).setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(final DialogInterface dialogInterface) {
                dialogInterface.dismiss();
                finish();
            }
        }).create().show();
    }
}

From source file:io.flutter.plugins.localauth.AuthenticationHelper.java

@SuppressLint("InflateParams")
private void showGoToSettingsDialog() {
    View view = LayoutInflater.from(activity).inflate(R.layout.go_to_setting, null, false);
    TextView message = (TextView) view.findViewById(R.id.fingerprint_required);
    TextView description = (TextView) view.findViewById(R.id.go_to_setting_description);
    message.setText((String) call.argument("fingerprintRequired"));
    description.setText((String) call.argument("goToSettingDescription"));
    Context context = new ContextThemeWrapper(activity, R.style.AlertDialogCustom);
    OnClickListener goToSettingHandler = new OnClickListener() {
        @Override/*from  w  w w .j  av a 2  s.c  om*/
        public void onClick(DialogInterface dialog, int which) {
            stop(false);
            activity.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
        }
    };
    OnClickListener cancelHandler = new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            stop(false);
        }
    };
    new AlertDialog.Builder(context).setView(view)
            .setPositiveButton((String) call.argument("goToSetting"), goToSettingHandler)
            .setNegativeButton((String) call.argument(CANCEL_BUTTON), cancelHandler).setCancelable(false)
            .show();
}

From source file:org.guohai.android.cta.CoordinateTalk.java

/** ? */
private void inita() {

    locationInfo = new LocationInfo();
    GSMManager gsm = new GSMManager(getApplicationContext(), locationInfo);
    GPSManager gps = new GPSManager(getApplicationContext(), locationInfo);
    LocationManagers = new ArrayList<ILocationManager>();
    LocationManagers.add(gsm);//from   w w  w .ja  v  a2s  .  c o m
    LocationManagers.add(gps);

    //??    
    mMainHandler = new Handler();

    openHandler();
    textCoordinate.setText("" + locationInfo.Latitude + "\n?" + locationInfo.Longitude
            + "\n" + locationInfo.Altitude);

    if (!gps.IsOpen()) {
        new AlertDialog.Builder(CoordinateTalk.this).setTitle(R.string.setting_gps_title)
                .setMessage(R.string.setting_gps_info)
                .setPositiveButton(R.string.gps_setting, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
                        startActivityForResult(intent, 0);

                    }
                }).setNegativeButton(R.string.jump_gps_setting, null).show();

        textCoordinate.setText("?GPS????");
    }
}

From source file:nl.hnogames.domoticz.Preference.Preference.java

private void setPreferences() {
    final android.preference.SwitchPreference MultiServerPreference = (android.preference.SwitchPreference) findPreference(
            "enableMultiServers");
    android.preference.Preference ServerSettings = findPreference("server_settings");
    android.preference.Preference PermissionsSettings = findPreference("permissionssettings");
    android.preference.Preference NotificationLogged = findPreference("notification_show_logs");
    android.preference.Preference fetchServerConfig = findPreference("server_force_fetch_config");
    android.preference.Preference resetApplication = findPreference("reset_settings");
    android.preference.ListPreference displayLanguage = (ListPreference) findPreference("displayLanguage");
    final android.preference.Preference registrationId = findPreference("notification_registration_id");
    android.preference.Preference GeoSettings = findPreference("geo_settings");
    android.preference.SwitchPreference WearPreference = (android.preference.SwitchPreference) findPreference(
            "enableWearItems");
    android.preference.Preference NFCPreference = findPreference("nfc_settings");
    android.preference.Preference QRCodePreference = findPreference("qrcode_settings");
    android.preference.Preference SpeechPreference = findPreference("speech_settings");
    android.preference.SwitchPreference EnableNFCPreference = (android.preference.SwitchPreference) findPreference(
            "enableNFC");
    android.preference.SwitchPreference EnableQRCodePreference = (android.preference.SwitchPreference) findPreference(
            "enableQRCode");
    android.preference.SwitchPreference EnableSpeechPreference = (android.preference.SwitchPreference) findPreference(
            "enableSpeech");
    android.preference.SwitchPreference EnableTalkBackPreference = (android.preference.SwitchPreference) findPreference(
            "talkBack");
    MultiSelectListPreference drawerItems = (MultiSelectListPreference) findPreference("enable_menu_items");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.SwitchPreference AlwaysOnPreference = (android.preference.SwitchPreference) findPreference(
            "alwayson");
    @SuppressWarnings("SpellCheckingInspection")
    android.preference.PreferenceScreen preferenceScreen = (android.preference.PreferenceScreen) findPreference(
            "settingsscreen");
    android.preference.PreferenceCategory premiumCategory = (android.preference.PreferenceCategory) findPreference(
            "premium_category");
    android.preference.Preference premiumPreference = findPreference("premium_settings");
    NotificationsMultiSelectListPreference notificationsMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "suppressNotifications");
    NotificationsMultiSelectListPreference alarmMultiSelectListPreference = (NotificationsMultiSelectListPreference) findPreference(
            "alarmNotifications");
    android.preference.SwitchPreference ThemePreference = (android.preference.SwitchPreference) findPreference(
            "darkTheme");
    android.preference.Preference FingerPrintSettingsPreference = findPreference("SecuritySettings");
    android.preference.SwitchPreference FingerPrintPreference = (android.preference.SwitchPreference) findPreference(
            "enableSecurity");

    if (!BuildConfig.DEBUG) {
        PreferenceCategory oAndroidAutoCategory = (android.preference.PreferenceCategory) findPreference(
                "androidautocategory");
        PreferenceScreen oNotificationScreen = (android.preference.PreferenceScreen) findPreference(
                "notificationscreen");
        oNotificationScreen.removePreference(oAndroidAutoCategory);
    }//  w ww .  j  ava 2  s  .  c  o m

    List<String> notifications = mSharedPrefs.getReceivedNotifications();
    if (notifications == null || notifications.size() <= 0) {
        notificationsMultiSelectListPreference.setEnabled(false);
        alarmMultiSelectListPreference.setEnabled(false);
    } else {
        notificationsMultiSelectListPreference.setEnabled(true);
        alarmMultiSelectListPreference.setEnabled(true);
    }

    PermissionsSettings
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    permissionHelper.openSettingsScreen();
                    return true;
                }
            });

    drawerItems.setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
            try {
                final HashSet selectedDrawerItems = (HashSet) newValue;
                if (selectedDrawerItems.size() < 1) {
                    showSnackbar(mContext.getString(R.string.error_atLeastOneItemInDrawer));
                    return false;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                return false;
            }
            return true;
        }
    });

    ThemePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_theme));
                        return false;
                    } else {
                        ((SettingsActivity) getActivity()).reloadSettings();
                        return true;
                    }
                }
            });

    MultiServerPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.multi_server));
                        return false;
                    }
                    return true;
                }
            });

    ServerSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (!MultiServerPreference.isChecked()) {
                Intent intent = new Intent(mContext, ServerSettingsActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(mContext, ServerListSettingsActivity.class);
                startActivity(intent);
            }
            return true;
        }
    });

    FingerPrintSettingsPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    mContext.startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
                    return true;
                }
            });

    fetchServerConfig
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    UsefulBits.getServerConfigForActiveServer(mContext, true, new ConfigReceiver() {
                        @Override
                        public void onReceiveConfig(ConfigInfo settings) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_success));
                        }

                        @Override
                        public void onError(Exception error) {
                            showSnackbar(mContext.getString(R.string.fetched_server_config_failed));
                        }
                    }, null);
                    return true;
                }
            });

    displayLanguage
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    showRestartMessage();
                    return true;
                }
            });

    registrationId.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (!PermissionsUtil.canAccessDeviceState(mContext)) {
                    permissionHelper.request(PermissionsUtil.INITIAL_DEVICE_PERMS);
                } else {
                    pushGCMRegistrationIds();
                }
            } else {
                pushGCMRegistrationIds();
            }
            return true;
        }
    });

    GeoSettings.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.geofence));
                return false;
            } else {
                Intent intent = new Intent(mContext, GeoSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    EnableNFCPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_nfc));
                        return false;
                    }

                    if (NfcAdapter.getDefaultAdapter(mContext) == null) {
                        showSnackbar(mContext.getString(R.string.nfc_not_supported));
                        return false;
                    }
                    return true;
                }
            });

    EnableQRCodePreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    }

                    return true;
                }
            });

    EnableSpeechPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    }
                    return true;
                }
            });

    EnableTalkBackPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_talk_back));
                        return false;
                    }
                    return true;
                }
            });

    NFCPreference.setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(android.preference.Preference preference) {
            if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                showPremiumSnackbar(getString(R.string.category_nfc));
                return false;
            } else {
                Intent intent = new Intent(mContext, NFCSettingsActivity.class);
                startActivity(intent);
                return true;
            }
        }
    });

    QRCodePreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_QRCode));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, QRCodeSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    SpeechPreference
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_Speech));
                        return false;
                    } else {
                        Intent intent = new Intent(mContext, SpeechSettingsActivity.class);
                        startActivity(intent);
                        return true;
                    }
                }
            });

    WearPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_wear));
                        return false;
                    }
                    return true;
                }
            });

    AlwaysOnPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object newValue) {
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.always_on_title));
                        return false;
                    }
                    return true;
                }
            });

    NotificationLogged
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    //show dialog
                    List<String> logs = mSharedPrefs.getLoggedNotifications();
                    if (logs != null && logs.size() > 0) {
                        Collections.reverse(logs);
                        new MaterialDialog.Builder(mContext)
                                .title(mContext.getString(R.string.notification_show_title))
                                .items((CharSequence[]) logs.toArray(new String[0])).show();
                    } else
                        UsefulBits.showSimpleToast(mContext, getString(R.string.notification_show_nothing),
                                Toast.LENGTH_LONG);
                    return true;
                }
            });

    //noinspection PointlessBooleanExpression
    if (!BuildConfig.LITE_VERSION) {
        preferenceScreen.removePreference(premiumCategory);
    } else {
        premiumPreference
                .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                    @Override
                    public boolean onPreferenceClick(android.preference.Preference preference) {
                        String packageID = mContext.getPackageName() + ".premium";
                        try {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + packageID)));
                        } catch (android.content.ActivityNotFoundException ignored) {
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("https://play.google.com/store/apps/details?id=" + packageID)));
                        }

                        return true;
                    }
                });
    }

    resetApplication
            .setOnPreferenceClickListener(new android.preference.Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(android.preference.Preference preference) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        new MaterialDialog.Builder(mContext).title(R.string.category_Reset)
                                .content(R.string.are_you_sure).positiveText(R.string.ok)
                                .negativeText(R.string.cancel)
                                .onPositive(new MaterialDialog.SingleButtonCallback() {
                                    @SuppressLint("NewApi")
                                    @Override
                                    public void onClick(@NonNull MaterialDialog dialog,
                                            @NonNull DialogAction which) {
                                        ((ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE))
                                                .clearApplicationUserData();
                                    }
                                }).show();
                    } else {
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
                    }
                    return true;
                }
            });

    FingerPrintPreference
            .setOnPreferenceChangeListener(new android.preference.Preference.OnPreferenceChangeListener() {
                @SuppressLint("NewApi")
                @Override
                public boolean onPreferenceChange(android.preference.Preference preference, Object o) {
                    if (mSharedPrefs.isStartupSecurityEnabled())
                        return true;
                    if (BuildConfig.LITE_VERSION || !mSharedPrefs.isAPKValidated()) {
                        showPremiumSnackbar(getString(R.string.category_startup_security));
                        return false;
                    } else {
                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                            UsefulBits.showSimpleToast(mContext, getString(R.string.fingerprint_not_supported),
                                    Toast.LENGTH_LONG);
                            return false;
                        }
                        if (!PermissionsUtil.canAccessFingerprint(mContext)) {
                            permissionHelper.request(PermissionsUtil.INITIAL_FINGERPRINT_PERMS);
                        } else {
                            FingerprintManager fingerprintManager = (FingerprintManager) mContext
                                    .getSystemService(Context.FINGERPRINT_SERVICE);
                            if (ActivityCompat.checkSelfPermission(mContext,
                                    Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
                                return false;
                            }
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (!fingerprintManager.isHardwareDetected()) {
                                    return false;
                                } else if (!fingerprintManager.hasEnrolledFingerprints()) {
                                    UsefulBits.showSimpleToast(mContext,
                                            getString(R.string.fingerprint_not_setup_in_android),
                                            Toast.LENGTH_LONG);
                                    return false;
                                } else {
                                    new MaterialDialog.Builder(mContext)
                                            .title(R.string.category_startup_security)
                                            .content(R.string.fingerprint_sure).positiveText(R.string.ok)
                                            .negativeText(R.string.cancel)
                                            .onPositive(new MaterialDialog.SingleButtonCallback() {
                                                @Override
                                                public void onClick(@NonNull MaterialDialog dialog,
                                                        @NonNull DialogAction which) {
                                                    mSharedPrefs.setStartupSecurityEnabled(true);
                                                    ((SettingsActivity) getActivity()).reloadSettings();
                                                }
                                            }).show();

                                    return false;
                                }
                            }
                        }
                    }
                    return false;
                }
            });
}

From source file:systems.soapbox.ombuds.client.ui.WalletTransactionsFragment.java

@Override
public void onWarningClick() {
    switch (warning()) {
    case BACKUP://from ww w. j a  v  a2  s.c  o  m
        ((WalletActivity) activity).handleBackupWallet();
        break;

    case STORAGE_ENCRYPTION:
        startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));
        break;
    }
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void launchSecuritySettings() {
    Intent launchSettingsIntent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
    startActivityForResult(launchSettingsIntent, REQUEST_ENABLE_UNKNOWN_SOURCES);
}

From source file:ua.mkh.settings.full.MainActivity.java

public void onClick(View v) {
    int id = v.getId();

    if (id == R.id.ButtonWifi) {
        Intent intent = new Intent(this, ActivityWifi.class);
        startActivity(intent);/*from   w  w  w . j a v a 2s .c  o m*/
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonBluetooth) {
        Intent intent1 = new Intent(this, ActivityBth.class);
        startActivity(intent1);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonSota) {
        Intent intent2 = new Intent(this, ActivitySota.class);
        startActivity(intent2);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonDisturb) {
        Intent intent11 = new Intent(this, ActivityDisturb.class);
        startActivity(intent11);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonOperator) {

        Intent settingsIntent = new Intent(this, ActivityOperator.class);
        startActivity(settingsIntent);
        overridePendingTransition(center_to_left, center_to_left2);

    }

    else if (id == R.id.ButtonZvuki) {
        Intent intent4 = new Intent(this, ActivityZvuki.class);
        startActivity(intent4);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonOboi) {
        Intent intent5 = new Intent(this, ActivityOboi.class);
        //intent5.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
        startActivity(intent5);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonOsnova) {
        Intent intent6 = new Intent(this, ActivityOsnova.class);
        intent6.putExtra("verintent", VerIntent);
        startActivity(intent6);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonPasscode) {
        Intent settingsIntent = new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS);
        startActivity(settingsIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    } else if (id == R.id.ButtonBattery) {
        Intent intent4 = new Intent(this, ActivityBattery.class);
        startActivity(intent4);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonPrivacy) {
        Intent settingsIntent = new Intent(android.provider.Settings.ACTION_PRIVACY_SETTINGS);
        startActivity(settingsIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ToggleButton01) {
        if (tb_am.isChecked())//means this is the request to turn ON AIRPLANE mode
        {
            if (OS > 16) {
                Intent settingsIntent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS);
                startActivity(settingsIntent);
                overridePendingTransition(center_to_left, center_to_left2);
            } else {
                Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);//Turning ON Airplane mode.
                Intent intent10 = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);//creating intent and Specifying action for AIRPLANE mode.
                intent10.putExtra("state", true);////indicate the "state" of airplane mode is changed to ON
                sendBroadcast(intent10);//Broadcasting and Intent
                //
                btn_sota.setTextColor(Color.parseColor("#808080"));
                btn_operator.setTextColor(Color.parseColor("#808080"));
                btn_gps.setTextColor(Color.parseColor("#808080"));
                btn_sota.setClickable(false);
                btn_operator.setClickable(false);
                btn_gps.setClickable(false);
            }
        } else//means this is the request to turn OFF AIRPLANE mode
        {
            if (OS > 16) {
                Intent settingsIntent = new Intent(android.provider.Settings.ACTION_AIRPLANE_MODE_SETTINGS);
                startActivity(settingsIntent);
                overridePendingTransition(center_to_left, center_to_left2);
            } else {
                Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0);//Turning OFF Airplane mode.
                Intent intent9 = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);//creating intent and Specifying action for AIRPLANE mode.
                intent9.putExtra("state", false);//indicate the "state" of airplane mode is changed to OFF
                sendBroadcast(intent9);//Broadcasting and Intent
                //
                btn_sota.setTextColor(Color.parseColor("#000000"));
                btn_operator.setTextColor(Color.parseColor("#000000"));
                btn_gps.setTextColor(Color.parseColor("#000000"));
                btn_sota.setClickable(true);
                btn_operator.setClickable(true);
                btn_gps.setClickable(true);
            }
        }
    }

    else if (id == R.id.ButtonGeo) {

        Intent intent8 = new Intent(this, ActivityGeo.class);
        startActivity(intent8);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonNotification) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(notifications_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonControl) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(control_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonMail) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(mail_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonNotes) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(notes_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonPhone) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(phone_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonMessages) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(messages_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonSafari) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(safari_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonMusic) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(music_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonCompass) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(compass_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonWeather) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(weather_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonGameCenter) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(gamecenter_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonMaps) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(maps_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.Button02) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(new1_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.Button03) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(new2_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.Button04) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(new3_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.Button05) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(new4_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonCloud) {
        Intent intent10 = new Intent(this, ActivityiCloud.class);
        startActivity(intent10);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonTunes) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(itunes_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.Button06) {
        Intent intent10 = new Intent(this, ActivityVPN.class);
        startActivity(intent10);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonDisplay) {
        Intent intent12 = new Intent(this, ActivityBrightness.class);
        startActivity(intent12);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonVk) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(vk_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonViber) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(viber_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonOk) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(ok_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonSkype) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(skype_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonWhatsapp) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(whatsapp_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonTwitter) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(twitter_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonFacebook) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(facebook_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }

    else if (id == R.id.ButtonInstagram) {
        Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(instagram_app);
        startActivity(LaunchIntent);
        overridePendingTransition(center_to_left, center_to_left2);
    }
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void askAndSetGpsEnabled() {
    if (GpsUtils.isGpsEnabled(getApplication())) {
        Log.d("askAndSetGpsEnabled(): GPS enabled");
        isGpsEnabled = true;/*from   w w w.  j  a v a2s .  c o m*/
        showAskForLocationSettingsDialog = false;
    } else {
        Log.d("askAndSetGpsEnabled(): GPS disabled, asking user");
        isGpsEnabled = false;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_want_enable_gps)
                .setPositiveButton(R.string.dialog_yes, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d("askAndSetGpsEnabled(): display settings");
                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        try {
                            startActivity(intent);
                            showAskForLocationSettingsDialog = true;
                        } catch (ActivityNotFoundException ex1) {
                            intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
                            try {
                                startActivity(intent);
                                showAskForLocationSettingsDialog = true;
                            } catch (ActivityNotFoundException ex2) {
                                Log.w("askAndSetGpsEnabled(): Could not open Settings to enable GPS");
                                MyApplication.getAnalytics().sendException(ex2, Boolean.FALSE);
                                ACRA.getErrorReporter().handleSilentException(ex2);
                                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
                                        .setMessage(R.string.dialog_could_not_open_gps_settings)
                                        .setPositiveButton(R.string.dialog_ok, null).create();
                                alertDialog.setCanceledOnTouchOutside(true);
                                alertDialog.setCancelable(true);
                                alertDialog.show();
                            }
                        } finally {
                            dialog.dismiss();
                        }
                    }
                }).setNegativeButton(R.string.dialog_no, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Log.d("askAndSetGpsEnabled(): cancel");
                        dialog.cancel();
                        if (GpsUtils.isGpsEnabled(getApplication())) {
                            Log.d("askAndSetGpsEnabled(): provider enabled in the meantime");
                            startCollectorServiceWithCheck();
                        } else {
                            isGpsEnabled = false;
                            showAskForLocationSettingsDialog = false;
                        }
                    }
                });
        AlertDialog dialog = builder.create();
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.show();
    }
}