• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Flutter 게시판 최신 android에서 원하는시간에 알람 띄우기가 계속 안됩니다

최신 android에서 원하는시간에 알람 띄우기가 계속 안됩니다

2 글 보임 - 1 에서 2 까지 (총 2 중에서)
  • 글쓴이
  • #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 월 전에 수정됐습니다.
    #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 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠