2 글 보임 - 1 에서 2 까지 (총 2 중에서)
-
글쓴이글
-
2025년 5월 19일 23:24 #139426
열심인참가자복잡한건 모두 제거하고 main에 필요한것만 넣어서 실행해봤는데 알림이 안옵니다 matchDateTimeComponents: null -> 이부분 지우라고 해서 지워도 똑같습니다. 설정부분까지 모두 올립니다
****** main.dart
import 'package:flutter/material.dart'; import 'notification.dart';
void main() { runApp( MaterialApp( home: MyApp() ) ); }
class MyApp extends StatefulWidget { const MyApp({super.key});
@override State<MyApp> createState() => _MyAppState(); }
class _MyAppState extends State<MyApp> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('알림 테스트')), floatingActionButton: FloatingActionButton( onPressed: () { showNotification2(); print("알림을 보냈습니다."); }, child: Text('알림'), ), body: Text('본문'), ); }
@override void initState() { super.initState(); initNotification(context); } }
****** notification.dart
showNotification2() async { tz.initializeTimeZones(); var androidDetails = const AndroidNotificationDetails( '유니크한 알림 ID', '알림종류 설명', priority: Priority.high, importance: Importance.max, color: Color.fromARGB(255, 255, 0, 0), ); var iosDetails = const DarwinNotificationDetails( presentAlert: true, presentBadge: true, presentSound: true, ); try { await notifications.zonedSchedule( 2, '제목2', '3초 후에 나타나는 알림', tz.TZDateTime.now(tz.local).add(Duration(seconds: 3)), NotificationDetails(android: androidDetails, iOS: iosDetails), androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle, ); print("알림 예약됨"); } on PlatformException catch (e) { print("알림 예약 실패: ${e.message}"); } }
****** pubspec.yaml 파일 dependencies: flutter: sdk: flutter
flutter_local_notifications: ^19.2.0 timezone: ^0.10.1
****** AndroidManifest.xml <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
****** build.gradle.kts
android { namespace = "com.example.flutter05_instagram" compileSdk = flutter.compileSdkVersion ndkVersion = flutter.ndkVersion
compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 isCoreLibraryDesugaringEnabled = true // 이부분 추가 }
// 맨 하단에 추가 dependencies { coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5") }
-
이 게시글은
열심인에 의해 1 월 전에 수정됐습니다.
2025년 5월 20일 12:44 #139437
codingapple키 마스터AndroidManifest 파일에 <uses-permission android:name="android.permission.USE_EXACT_ALARM" /> 추가해보거나
if (Platform.isAndroid) { final AndroidFlutterLocalNotificationsPlugin? androidImplementation = notifications.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>();
final granted = await androidImplementation?.requestExactAlarmsPermission(); if (granted == true) { print("권한받음"); } else { print("권한거절"); } }
이런거 initNotification() 함수 안에 추가해봅시다
-
이 게시글은
-
글쓴이글
2 글 보임 - 1 에서 2 까지 (총 2 중에서)
- 답변은 로그인 후 가능합니다.