[Flutter] 로컬 알림 (local_notifycation) 안드로이드 푸시 권한 이슈 (푸시가 안 올 때)
flutter_local_notification 패키지를 사용하여 앱 내에 로컬 알림을 사용 하기위해 열심히 구글링 했다..
예제 소스도 보면서 열심히 구현 하였지만 빼먹은소스(?)도 없는데 알람이 안오는 것이다 ㅠ
아무리 구글링해도 나오지 않아 결국 공식 문서를 보니…
flutter_local_notification 패키지를 사용하여 앱 내에 로컬 알림을 사용 하기위해 열심히 구글링 했다..
예제 소스도 보면서 열심히 구현 하였지만 빼먹은소스(?)도 없는데 알람이 안오는 것이다 ㅠ
아무리 구글링해도 나오지 않아 결국 공식 문서를 보니…
(공식문서 : https://pub.dev/packages/flutter_local_notifications#-android-setup)
flutter_local_notifications | Flutter Package
A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform.
pub.dev
요약 하자면 안드로이드13 버전 이상 부터는 사용자에게 반드시 앱 표시 권한 요청을 물어봐야 한다는 것이다!!
이전 버전까지는 자동 권한 수락 이여서 해당 코드가 필요 없었고 iOS의 경우에만 권한 요청을 물어보았었다..
Requesting permissions on Android 13 or higher
From Android 13 (API level 33) onwards, apps now have the ability to display a prompt where users can decide if they want to grant an app permission to show notifications. For further reading on this matter read https://developer.android.com/guide/topics/ui/notifiers/notification-permission. To support this applications need target their application to Android 13 or higher and the compile SDK version needs to be at least 33 (Android 13). For example, to target Android 13, update your app's build.gradle file to have a targetSdkVersion of 33. Applications can then call the following code to request the permission where the requestPermission method is associated with the AndroidFlutterLocalNotificationsPlugin class (i.e. the Android implementation of the plugin)
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>().requestPermission();

참고로..
android/build.gradle 에서 compileSdkVersion 을 33으로도 수정 해주자.
The plugin also requires that the compieSdkVersion in your application's Gradle file is set to 33:
android { compileSdkVersion 33 ... }
안될땐 공식문서를 꼼꼼히 읽어봐야겠다..!!