알림 권한 요청 | Push | Appbox Android SDK 가이드
알림 권한 요청
알림 권한 요청
AppBox.requestPushPermission(activity, callback)
Kotlin
1
AppBox.requestPushPermission(this) { granted, error ->
2
when {
3
error is AppBoxPushPromptInterruptedException -> Unit // 거부가 아님
4
granted == true -> enablePushUi()
5
else -> showNotificationSettingsGuide()
6
}
7
}
1
AppBox.requestPushPermission(this, new AppBoxValueCallback<Boolean>() {
2
@Override
3
public void onComplete(Boolean granted, Throwable error) {
4
if (error instanceof AppBoxPushPromptInterruptedException) {
5
return; // 거부가 아님
6
}
7
if (Boolean.TRUE.equals(granted)) {
8
enablePushUi();
9
} else {
10
showNotificationSettingsGuide();
11
}
12
}
13
});
Request 항목 정의
| Request 항목 | 필수여부 | 설명 | 기본값 |
|---|---|---|---|
| activity | 필수 | 권한 다이얼로그를 표시할 foreground Activity. Application context는 쓸 수 없습니다 | - |
| callback | 필수 | AppBoxValueCallback<Boolean> | - |
Response 항목 정의
| Response 결과값 | |
|---|---|
granted = true, error = null | 사용자가 허용 |
granted = false, error = null | 사용자가 거부 |
granted = null, error = AppBoxPushPromptInterruptedException | 사용자가 응답하지 않고 프롬프트가 종료됨 |
| 오류 | AppBoxPushPromptInterruptedException: 홈 화면 이동, 화면 잠금으로 프롬프트가 응답 없이 닫힘 |
응답 없이 종료된 상태를 거부로 저장하지 마세요. 사용자의 의사 표시가 아니며, 거부로 저장하면 사용자를 잘못 옵트아웃시킵니다. Android 13 이상에서는 시스템 다이얼로그가 표시됩니다. Android 12 이하에서는 다이얼로그 없이 현재 알림 활성화 상태가 반환됩니다. 예외적으로 appbox-push artifact만 있으면 동작합니다.