Open settings activity

Start the App Settings Activity so that the user can change settings related to the application, such as permissions.

private fun startAppSettingsConfigActivity() {
    val i = Intent().apply {
        action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
        addCategory(Intent.CATEGORY_DEFAULT)
        data = Uri.parse("package:" + requireActivity().packageName)
        addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
        addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
    }
    requireActivity().startActivity(i)
}

Usage

Sample usage:

private fun showPermissionsExplanation(openSystemAppInfo: Boolean) {
    var listener: DialogInterface.OnClickListener? = null
    if (openSystemAppInfo) {
        listener = DialogInterface.OnClickListener { _, _ ->
            // will be executed if user clicks OK button
            startAppSettingsConfigActivity()
        }
    }
    context?.let {
        AlertDialog.Builder(it)
            .setMessage(getString(R.string.permission_required))
            .setPositiveButton(getString(R.string.label_Ok), listener)
            .create()
            .show()
    }
}