Flutter
패키지
Local Notification

Local Notification

build.gradle 수정

android/app/build.gradle
android {
  compileSdkVersion 33
  defaultConfig {
    multiDexEnabled true
  }

  compileOptions {
    // Flag to enable support for the new language APIs
    coreLibraryDesugaringEnabled true
    // Sets Java compatibility to Java 8
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
}

dependencies {
  implementation 'androidx.window:window:1.0.0'
  implementation 'androidx.window:window-java:1.0.0'
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.2.2'
}
android/build.gradle
buildscript {
    ...
    
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.1'
    }
}

AndroidManifest.xml 수정

manifest tags

  • 기기가 재부팅 될 때 알림 발생하게 스케쥴 등록함
android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
  • 정확한 타이밍에 알림이 필요한 경우
  1. 사용자 권한을 요청하는 방법
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
  1. 사용자에게 권한을 부여하라는 메시지가 표시되지는 않지만, USE_EXACT_ALARM 권한에 대한 공식 안드로이드 문서(여기 및 여기 참조)에 따르면 이 권한을 사용하려면 앱이 안드로이드 13(API 레벨 33) 이상을 대상으로 해야 하며 앱을 게시하는 데 사용된 앱스토어의 승인 및 감사를 받아야 할 수 있습니다.
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
full screen notification
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

application tags

<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
        <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
    </intent-filter>
</receiver>
use notification action
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />

activity tags

기본에 존재하는 activity 태그 아래에 코드 추가.
기기가 잠겨있을 때 화면이 켜지도록 한다.

<activity
  ...
  android:showWhenLocked="true"
  android:turnScreenOn="true"
  ...
  >