private
final
String USER_MENDATORY_KEY =
"your_clear_key_name"
;
private
final
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(
this
);
private
void
checkUserMendatoryOption() {
if
(userMendatoryOptionConfigured())
return
;
showUserMendatoryOptionDialog();
}
private
boolean
userMendatoryOptionConfigured() {
return
preferences.getBoolean(USER_MENDATORY_KEY,
false
);
}
private
void
showUserMendatoryOptionDialog() {
AlertDialog.Builder alert =
new
androidx.appcompat.app.AlertDialog.Builder(MainActivity.
this
);
alert.setPositiveButton { dialog,
int
which ->
userMendatoryOptionAccepted()
}
.setNegativeButton(
"거부"
,
dialog,
int
which -> {
userMendatoryOptionDenied()
}
alert.setMessage(
"예이예이예"
);
alert.show();
}
private
void
userMendatoryOptionAccepted() {
preferences.editor()
.putBoolean(USER_MENDATORY_KEY,
true
)
}
private
void
userMendatoryOptionDenied() {
Toast.makeText(MainActivity.
this
,
"필수권한이 거부되어 앱을 종료합니다"
, Toast.LENGTH_SHORT).show();
finish();
}
public
class
OnboardingOptionChecker {
private
final
String USER_MENDATORY_KEY =
"your_clear_key_name"
;
private
final
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(
this
);
public
void
validate(MendatoryOptionRequiredCallback callback) {
}
}
final
OnboardingOptionChecker checker =
new
OnboardingOptionChecker();
checker.validate {
showUserMendatoryOptionDialog();
}