title: Android Alarm Manager is not working for Flutter Project App
body: <p><a href="https://i.stack.imgur.com/LCnkJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LCnkJ.png" alt="Error" /></a>
  I have installed the Android Alarm Manager plugin in my new Flutter app. I tried using the example code of Plugin, but it gives an error in console.</p>
  <p>Please suggest how to make the Android Alarm Manager plugin work.
  How do I integrate Dart's android_alarm_manager to the app so that users get alarm when the time they picked in the schedule reaches?</p>
  <p>I use the code from this link:
  <a href="https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager" rel="nofollow noreferrer">https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager</a></p>
  <p><code>main.dart</code>:</p>
  <pre><code>import 'dart:isolate';
  import 'package:android_alarm_manager/android_alarm_manager.dart';
  import 'package:flutter/material.dart';
      
  void printHello() {
    final DateTime now = DateTime.now();
    final int isolateId = Isolate.current.hashCode;
    print(&quot;[$now] Hello, world! isolate=${isolateId} function='$printHello'&quot;);
  }
  
  void main() async {
    final int helloAlarmID = 0;
    await AndroidAlarmManager.initialize();
    runApp(MaterialApp(home: Application()));
    await AndroidAlarmManager.periodic(const Duration(minutes: 1), helloAlarmID, printHello);
  }
  
  class Application extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Container(),
      );
    }
  }
  </code></pre>
  <p><code>Application.java</code>:</p>
  <pre><code>package io.flutter.plugins.androidalarmmanagerexample;
  import io.flutter.app.FlutterApplication;
  import io.flutter.plugin.common.PluginRegistry;
  import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
  import io.flutter.plugins.GeneratedPluginRegistrant;
      
  public class Application extends FlutterApplication implements PluginRegistrantCallback {
      @Override
      public void onCreate() {
          super.onCreate();
      
          AlarmService.setPluginRegistrant(this);
      }
  
      @Override
      public void registerWith(PluginRegistry registry) {
          GeneratedPluginRegistrant.registerWith(registry);
      }
  }               
  </code></pre>
  <p>When I run this code it prints the following error to console:</p>
  <pre><code>E/flutter ( 6831): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke interface method 'void io.flutter.plugin.common.PluginRegistry$PluginRegistrantCallback.registerWith(io.flutter.plugin.common.PluginRegistry)' on a null object reference, null)
  E/flutter ( 6831): #0      JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:149:7)
  E/flutter ( 6831): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #2      AndroidAlarmManager.initialize (package:android_alarm_manager/android_alarm_manager.dart:76:10)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #3      main (package:alarmdemo/main.dart:12:29)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #4      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:189:25)
  E/flutter ( 6831): #5      _rootRun (dart:async/zone.dart:1124:13)
  E/flutter ( 6831): #6      _CustomZone.run (dart:async/zone.dart:1021:19)
  E/flutter ( 6831): #7      _runZoned (dart:async/zone.dart:1516:10)
  E/flutter ( 6831): #8      runZoned (dart:async/zone.dart:1500:12)
  E/flutter ( 6831): #9      _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:180:5)
  E/flutter ( 6831): #10     _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:300:19)
  E/flutter ( 6831): #11     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  E/flutter ( 6831): 
  E/flutter ( 6831): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method AlarmService.initialized on channel plugins.flutter.io/android_alarm_manager_background)
  E/flutter ( 6831): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:300:7)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #1      _alarmManagerCallbackDispatcher (package:android_alarm_manager/android_alarm_manager.dart:49:12)
  E/flutter ( 6831): #2      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:189:25)
  E/flutter ( 6831): #3      _rootRun (dart:async/zone.dart:1124:13)
  E/flutter ( 6831): #4      _CustomZone.run (dart:async/zone.dart:1021:19)
  E/flutter ( 6831): #5      _runZoned (dart:async/zone.dart:1516:10)
  E/flutter ( 6831): #6      runZoned (dart:async/zone.dart:1500:12)
  E/flutter ( 6831): #7      _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:180:5)
  E/flutter ( 6831): #8      _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:300:19)
  E/flutter ( 6831): #9      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  E/flutter ( 6831): 
  </code></pre>
  <p>This is my updated code:</p>
  <p><code>main.dart</code>:</p>
  <pre><code>void printHello() {
    final DateTime now = new DateTime.now();
    final int isolateId = Isolate.current.hashCode;
    print(&quot;[$now] Hello, world! isolate=${isolateId} 
        function='$printHello'&quot;);
  }
  
  void main() async {
    runApp(MaterialApp(home: Application()));
  }
      
  class Application extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Container(
          child: Center(
            child: RaisedButton(
              child: Text('Hello'),
              onPressed: () {
                runAlarm();
              },
            ),
          ),
        ),
      );
    }
  
    void runAlarm() {
      AndroidAlarmManager.oneShot(
        Duration(seconds: 10),
        0,
        printHello,
        wakeup: true,
      ).then((val) =&gt; print(val));
    }
  
    static void alarmTest() {
      print(&quot;test&quot;);
    }
  }
  </code></pre>
  <p>It does not print any error to console but it prints the following two lines:</p>
  <pre><code>E/AlarmService(11943): Fatal: failed to find callback
  I/AlarmService(11943): AlarmService has not yet started.
  </code></pre>
  <p>I also tried initializing the alarm manager but it prints an error to console:</p>
  <pre><code>void runAlarm() {
    AndroidAlarmManager.periodic(
      Duration(seconds: 10),
      0,
      printHello,
      wakeup: true,
    ).then((val) =&gt; print(val)).catchError((e) {
      print(e);
    });
  }
  </code></pre>
  <p>Error:</p>
  <pre><code>E/flutter ( 6831): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke interface method 'void io.flutter.plugin.common.PluginRegistry$PluginRegistrantCallback.registerWith(io.flutter.plugin.common.PluginRegistry)' on a null object reference, null)
  E/flutter ( 6831): #0      JSONMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:149:7)
  E/flutter ( 6831): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #2      AndroidAlarmManager.initialize (package:android_alarm_manager/android_alarm_manager.dart:76:10)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #3      main (package:alarmdemo/main.dart:12:29)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #4      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:189:25)
  E/flutter ( 6831): #5      _rootRun (dart:async/zone.dart:1124:13)
  E/flutter ( 6831): #6      _CustomZone.run (dart:async/zone.dart:1021:19)
  E/flutter ( 6831): #7      _runZoned (dart:async/zone.dart:1516:10)
  E/flutter ( 6831): #8      runZoned (dart:async/zone.dart:1500:12)
  E/flutter ( 6831): #9      _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:180:5)
  E/flutter ( 6831): #10     _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:300:19)
  E/flutter ( 6831): #11     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  E/flutter ( 6831): 
  E/flutter ( 6831): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method AlarmService.initialized on channel plugins.flutter.io/android_alarm_manager_background)
  E/flutter ( 6831): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:300:7)
  E/flutter ( 6831): &lt;asynchronous suspension&gt;
  E/flutter ( 6831): #1      _alarmManagerCallbackDispatcher (package:android_alarm_manager/android_alarm_manager.dart:49:12)
  E/flutter ( 6831): #2      _runMainZoned.&lt;anonymous closure&gt;.&lt;anonymous closure&gt; (dart:ui/hooks.dart:189:25)
  E/flutter ( 6831): #3      _rootRun (dart:async/zone.dart:1124:13)
  E/flutter ( 6831): #4      _CustomZone.run (dart:async/zone.dart:1021:19)
  E/flutter ( 6831): #5      _runZoned (dart:async/zone.dart:1516:10)
  E/flutter ( 6831): #6      runZoned (dart:async/zone.dart:1500:12)
  E/flutter ( 6831): #7      _runMainZoned.&lt;anonymous closure&gt; (dart:ui/hooks.dart:180:5)
  E/flutter ( 6831): #8      _startIsolate.&lt;anonymous closure&gt; (dart:isolate/runtime/libisolate_patch.dart:300:19)
  E/flutter ( 6831): #9      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
  E/flutter ( 6831): 
  </code></pre>
  <p><a href="https://i.stack.imgur.com/6xnW6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6xnW6.png" alt="enter image description here" /></a></p>