Created
November 15, 2017 03:21
-
-
Save gotoark/392af3a3bdd673a06b8a8cb623ae4be0 to your computer and use it in GitHub Desktop.
android 6.0.1 to ask the WRITE_SETTINGS permission Ref: https://forum.xda-developers.com/s7-edge/help/setactualdefaultringtoneuri-t3387159
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean checkMyPermission(boolean isSecondTimeCheck) { | |
String dialogTitle = "need WRITE_SETTINGS permission"; | |
if (isSecondTimeCheck) dialogTitle = "you deny the permission"; | |
String btnTitle = "ok", if (isSecondTimeCheck) btnTitle = "try again"; | |
if (Build.VERSION.SDK_INT >= 23) { | |
if (!Settings.System.canWrite(this)) { | |
new AlertDialog.Builder(mContext).setMessage(dialogTit le).setPositiveButton(btnTitle, new DialogInterface.OnClickListener() { | |
@override | |
public void onClick(DialogInterface dialog, int which) { | |
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName())); | |
startActivityForResult(intent, REQUEST_CODE_PERMISSION); | |
} | |
}).setNegativeButton("cancel", null).create().show(); | |
return false; | |
} | |
return true; | |
} else { | |
int hasWriteContactsPermission = ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_SETTINGS); | |
if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) { | |
new AlertDialog.Builder(mContext).setMessage(dialogTit le).setPositiveButton(btnTitle, new DialogInterface.OnClickListener() { | |
@override | |
public void onClick(DialogInterface dialog, int which) { | |
Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName())); | |
startActivityForResult(intent, REQUEST_CODE_PERMISSION); | |
} | |
}).setNegativeButton("cancel", null).create().show(); | |
return false; | |
} else { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment