Example usage for android.provider Settings ACTION_MANAGE_WRITE_SETTINGS

List of usage examples for android.provider Settings ACTION_MANAGE_WRITE_SETTINGS

Introduction

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

Prototype

String ACTION_MANAGE_WRITE_SETTINGS

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

Click Source Link

Document

Activity Action: Show screen for controlling which apps are allowed to write/modify system settings.

Usage

From source file:com.pranavpandey.smallapp.permission.PermissionWriteSystemSettings.java

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

    openPermissionSettings(Settings.ACTION_MANAGE_WRITE_SETTINGS);
}

From source file:jmri.enginedriver.intro_write_settings.java

@SuppressWarnings("ConstantConditions")
@Override//from   w  w w  . j a  v a2  s  .c o m
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    Log.d("Engine_Driver", "intro_write_settings");
    super.onActivityCreated(savedInstanceState);

    Button settingsButton = getView().findViewById(R.id.intro_write_settings_launch);
    settingsButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_MANAGE_WRITE_SETTINGS);
            Uri uri = Uri.fromParts("package", getActivity().getApplicationContext().getPackageName(), null);
            intent.setData(uri);
            getActivity().startActivity(intent);
        }
    });

}

From source file:com.whitebyte.hotspotcontrolexample.Main.java

/** Called when the activity is first created. */
@Override/*from w w  w .j  a  v  a 2  s . co  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    int PERMISSION_ALL = 1;
    String[] PERMISSIONS = { Manifest.permission.INTERNET, Manifest.permission.CHANGE_WIFI_STATE,
            Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.CHANGE_NETWORK_STATE, Manifest.permission.WRITE_SETTINGS };

    ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
    textView1 = (TextView) findViewById(R.id.textView1);
    wifiApManager = new WifiApManager(this);
    //
    Boolean retVal = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        retVal = Settings.System.canWrite(this);
    }

    if (retVal) {
        Toast.makeText(this, "Write allowed :-)", Toast.LENGTH_LONG).show();
    } else {
        Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
        intent.setData(Uri.parse("package:" + this.getPackageName()));
        startActivity(intent);
    }

    //      scan();

}

From source file:com.pranavpandey.smallapp.permission.PermissionWriteSystemSettings.java

private void buildPermissionsDialog() {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    View view = getLayoutInflater().inflate(R.layout.sas_dialog_permission, new LinearLayout(this), false);
    ViewGroup frame = (ViewGroup) view.findViewById(R.id.permission_frame);

    String label = getApplicationInfo().loadLabel(getPackageManager()).toString();
    ((TextView) view.findViewById(R.id.permission_message)).setText(
            String.format(getString(R.string.sas_format_next_line), getString(R.string.sas_perm_request_desc),
                    String.format(getString(R.string.sas_perm_write_system_settings_info), label)));

    frame.addView(new PermissionItem(this, ContextCompat.getDrawable(this, R.drawable.sas_ic_menu_settings),
            getString(R.string.sas_perm_write_system_settings),
            getString(R.string.sas_perm_write_system_settings_desc)));

    try {//from   w w  w  . ja  v  a2  s.  com
        alertDialogBuilder.setIcon(
                DynamicTheme.createDialogIcon(this, getPackageManager().getApplicationIcon(getPackageName())));
    } catch (Exception e) {
        e.printStackTrace();
    }
    alertDialogBuilder.setTitle(label)
            .setPositiveButton(R.string.sas_perm_continue, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    openPermissionSettings(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    finishPermissionsChecker();
                }
            }).setCancelable(false);

    final AlertDialog dialog = alertDialogBuilder.create();
    dialog.setView(view, 0, SmallUtils.getDialogTopPadding(this), 0, 0);

    showPermissionDialog(dialog);
}

From source file:net.canking.permissiondemo.PermissionUtils.java

/**
 * WRITE_SETTINGS ??/*from ww w.j  ava 2 s  .  com*/
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingSystemPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.System.canWrite(activity)) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + activity.getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.System.canWrite(fragment.getContext())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + fragment.getContext().getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            fragment.startActivityForResult(intent, req);
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.lvbo.template.common.Utils.PermissionUtils.java

/**
 * WRITE_SETTINGS ??/*from ww  w .  jav  a 2  s  . c  o  m*/
 * @param cxt
 * @param req
 * @return
 */
@TargetApi(23)
public static boolean checkSettingSystemPermission(Object cxt, int req) {
    if (cxt instanceof Activity) {
        Activity activity = (Activity) cxt;
        if (!Settings.System.canWrite(activity)) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + activity.getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activity.startActivityForResult(intent, req);
            return false;
        }
    } else if (cxt instanceof Fragment) {
        Fragment fragment = (Fragment) cxt;
        if (!Settings.System.canWrite(fragment.getContext())) {
            Log.i(TAG, "Setting not permission");

            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
            intent.setData(Uri.parse("package:" + fragment.getContext().getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            fragment.startActivityForResult(intent, req);
            return false;
        }
    } else {
        throw new RuntimeException("cxt is net a activity or fragment");
    }

    return true;
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void settingPermission(@NonNull Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.writesetting).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//  w ww. j a  v  a 2  s. c o m
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, WRITESETTINGS);
                            } else {
                                Toast.makeText(activity, "No app found to handle settings write permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setSettings(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            builder.show();
        }
    }
}

From source file:com.jmstudios.redmoon.fragment.ShadesFragment.java

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

    addPreferencesFromResource(R.xml.preferences);

    String darkThemePrefKey = getString(R.string.pref_key_dark_theme);
    String lowerBrightnessPrefKey = getString(R.string.pref_key_control_brightness);
    String automaticFilterPrefKey = getString(R.string.pref_key_automatic_filter);
    String automaticTurnOnPrefKey = getString(R.string.pref_key_custom_start_time);
    String automaticTurnOffPrefKey = getString(R.string.pref_key_custom_end_time);
    String locationPrefKey = getString(R.string.pref_key_location);
    String otherCategoryPrefKey = getString(R.string.pref_key_other);

    PreferenceScreen prefScreen = getPreferenceScreen();
    darkThemePref = (SwitchPreference) prefScreen.findPreference(darkThemePrefKey);
    lowerBrightnessPref = (SwitchPreference) prefScreen.findPreference(lowerBrightnessPrefKey);
    automaticFilterPref = (ListPreference) prefScreen.findPreference(automaticFilterPrefKey);
    automaticTurnOnPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOnPrefKey);
    automaticTurnOffPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOffPrefKey);
    locationPref = (LocationPreference) prefScreen.findPreference(locationPrefKey);
    otherPrefCategory = prefScreen.findPreference(otherCategoryPrefKey);

    darkThemePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override/*from w  ww  . ja  v a2s.  c  o m*/
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            getActivity().recreate();
            return true;
        }
    });

    if (android.os.Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(getContext()))
        lowerBrightnessPref.setChecked(false);

    lowerBrightnessPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean checked = (Boolean) newValue;
            if (checked && android.os.Build.VERSION.SDK_INT >= 23 && !Settings.System.canWrite(getContext())) {
                Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                        Uri.parse("package:" + getContext().getPackageName()));
                startActivityForResult(intent, -1);
                return false;
            }

            return true;
        }
    });

    boolean custom = automaticFilterPref.getValue().toString().equals("custom");
    automaticTurnOnPref.setEnabled(custom);
    automaticTurnOffPref.setEnabled(custom);
    boolean sun = automaticFilterPref.getValue().toString().equals("sun");
    locationPref.setEnabled(sun);

    automaticFilterPref.setSummary(automaticFilterPref.getEntry());

    onAutomaticFilterPreferenceChange(automaticFilterPref, automaticFilterPref.getValue().toString());

    automaticFilterPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            return onAutomaticFilterPreferenceChange(preference, newValue);
        }
    });

    locationPref.setOnLocationChangedListener(new LocationPreference.OnLocationChangedListener() {
        @Override
        public void onLocationChange() {
            if (automaticFilterPref.getValue().equals("sun")) {
                updateFilterTimesFromSun();
            }
        }
    });

}

From source file:com.wubydax.dbeditor.TableValuesFragment.java

private void showDialog(final String key, final String value, final int position) {
    @SuppressLint("InflateParams")
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_layout, null, false);
    TextView keyText = (TextView) view.findViewById(R.id.textKey);
    final EditText editText = (EditText) view.findViewById(R.id.valueEditText);
    final ScrollView scroll = (ScrollView) view.findViewById(R.id.ScrollView1);
    if (value.matches("\\d+(?:\\.\\d+)?")) {
        editText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
        editText.setSingleLine(true);/*from ww  w.j a v a  2s .  co  m*/
    } else {
        editText.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setHint(getResources().getString(R.string.enter_string));
    }
    keyText.setText(key);
    editText.setText(value);
    editText.setSelection(editText.getText().length());
    scroll.post(new Runnable() {
        @Override
        public void run() {
            scroll.fullScroll(View.FOCUS_DOWN);
        }
    });
    new AlertDialog.Builder(getActivity()).setTitle(getResources().getString(R.string.change_value))
            .setView(view).setNegativeButton(android.R.string.cancel, null)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String newValue = editText.getText().toString();
                    boolean isGranted = Settings.System.canWrite(getActivity());
                    if (!isGranted) {
                        Intent grantPermission = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
                        startActivity(grantPermission);
                    } else {
                        switch (mTableName) {
                        case "system":
                            Settings.System.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        case "global":
                            Settings.Global.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        case "secure":
                            Settings.Secure.putString(getActivity().getContentResolver(), key, newValue);
                            break;
                        }
                        mList.get(position).value = newValue;
                    }
                    mRecyclerView.getAdapter().notifyDataSetChanged();
                }
            }).show();
}

From source file:com.example.captain_miao.grantap.ShadowPermissionActivity.java

@TargetApi(value = Build.VERSION_CODES.M)
public void requestPermissions(List<String> needPermissions) {
    //first SYSTEM_ALERT_WINDOW
    if (!hasRequestedSystemAlertWindow && !TextUtils.isEmpty(permissionSystemAlertWindow)) {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                Uri.parse("package:" + packageName));
        startActivityForResult(intent, REQ_CODE_REQUEST_SYSTEM_ALERT_WINDOW);
    } else if (!hasRequestedWriteSettings && !TextUtils.isEmpty(permissionWriteSettings)) {
        //second WRITE_SETTINGS
        Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + packageName));
        startActivityForResult(intent, REQ_CODE_REQUEST_WRITE_SETTING);
    } else {//from  www  . j  av a2 s .c  o m
        //other permission
        ActivityCompat.requestPermissions(this, needPermissions.toArray(new String[needPermissions.size()]),
                REQ_CODE_PERMISSION_REQUEST);
    }
}