plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

android_alarm_manager_plus 1.0.1 not triggering my callback

Open mpoirier101 opened this issue 5 years ago • 2 comments

UPDATE:

I cannot run the example but I created a GitHub project with plain Flutter Sample app with the code I use:

https://github.com/mpoirier101/AlarmTest

Tried both top level and static function. I get no error, but the callback is never triggered... I probably don't understand how to use this plugin properly...

=============================

Hello!

Followed the example instructions for this plugin successfully but only the FIRST debug session... So I know it CAN work. Now, I get no error but the alarm is never triggered ?!? You are my last resort, google did not provide solution and I don't have any hair left to pull...

Debuging on my connected device: Samsung model SM-J120W Android version 6.0.1

android_alarm_manager_plus 1.0.1

AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
...
<service
  android:name="io.flutter.plugins.androidalarmmanager.AlarmService"
  android:permission="android.permission.BIND_JOB_SERVICE"
  android:exported="false"/>
<receiver
  android:name="io.flutter.plugins.androidalarmmanager.AlarmBroadcastReceiver"
  android:exported="false"/>
<receiver
  android:name="io.flutter.plugins.androidalarmmanager.RebootBroadcastReceiver"
  android:enabled="false">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED"/>
  </intent-filter>
</receiver>

in main.dart:

// top level function is never called :-(
void callback() {
  final DateTime now = DateTime.now();
  final int isolateId = Isolate.current.hashCode;
  print("[$now] Hello, world! isolate=$isolateId function='$callback'");
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  bool test = await AndroidAlarmManager.initialize();
  print('initialize test = $test'); // **_returns true_**
  ...
}

in my home page:

Center(
  child: Switch(
  value: isOn,
  onChanged: (value) {
    setState(() {
      isOn = value;
    });
    if (isOn == true) {
      AndroidAlarmManager.periodic(Duration(seconds: 10), alarmId, **callback**, startAt: DateTime.now(), exact: true, wakeup: true)
          .then((value) => print('Alarm Timer Started = $value')); // **_returns true_**
    } else {
      AndroidAlarmManager.cancel(alarmId).then((value) => print('Alarm Timer Canceled = $value'));
    }
  },
)),

flutter doctor:

[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.985], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Chrome - develop for the web
[√] Android Studio
[√] VS Code (version 1.56.2)
[√] Connected device (3 available)

• No issues found!

Is there any missing information that I can provide ?

Thanks for any help/sugestion you can provide !

Originally posted by @mpoirier101 in https://github.com/fluttercommunity/plus_plugins/discussions/267

mpoirier101 avatar Jun 07 '21 16:06 mpoirier101

Found the problem. I kept the old AndroidManifest entries for "android_alarm_manager".

Now switched to "android_alarm_manager_plus" entries:

        <service
            android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <receiver
            android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
            android:exported="false" />
        <receiver
            android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
            android:enabled="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>

mpoirier101 avatar Jun 08 '21 13:06 mpoirier101

thanks for the update! as I see the documentation was already correct, so closing this issue

miquelbeltran avatar Jun 10 '21 05:06 miquelbeltran