plus_plugins
plus_plugins copied to clipboard
[Question]: Repeat every 10 seconds not working
What is your question?
I use the following code `void printHello() { final DateTime now = DateTime.now(); final int isolateId = Isolate.current.hashCode; print("[$now] Hello, world! isolate=${isolateId} function='$printHello'"); }
void main() async {
WidgetsFlutterBinding.ensureInitialized(); await AndroidAlarmManager.initialize();
runApp(MyApp());
final int helloAlarmID = 0; await AndroidAlarmManager.periodic(const Duration(seconds: 1), helloAlarmID, printHello);
}` But the printhello function is executed only once and this function is not repeated
to be sure, check that your AndroidManifest is complete: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/android_alarm_manager_plus/README.md#getting-started and also, your code says seconds: 1
not seconds: 10
. The native AlarmManager is not super reliable either.
to be sure, check that your AndroidManifest is complete: https://github.com/fluttercommunity/plus_plugins/blob/main/packages/android_alarm_manager_plus/README.md#getting-started and also, your code says
seconds: 1
notseconds: 10
. The native AlarmManager is not super reliable either.
this is my AndroidManifest code:
`
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- For apps with targetSDK=31 (Android 12) -->
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM"/>
<service
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="false"/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.AlarmBroadcastReceiver"
android:exported="false"/>
<receiver
android:name="dev.fluttercommunity.plus.androidalarmmanager.RebootBroadcastReceiver"
android:enabled="false"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
` still not working
I think it is related to https://github.com/fluttercommunity/plus_plugins/pull/810 and should be fixed in next release
I think it is related to #810 and should be fixed in next release
But it does not work when the phone is locked
If you are still referencing to the code you shared in the first message then I would suggest you to look at other available parameters to setup periodic alarm and add those which you need for your use case: https://pub.dev/documentation/android_alarm_manager_plus/latest/android_alarm_manager_plus/AndroidAlarmManager/periodic.html
In general, note that AlarmManager isn't a reliable solution, especially when phone is locked and Doze mode and other OS optimisations kick in. I would suggest to read the official documentation https://developer.android.com/reference/android/app/AlarmManager about it where some of precautions are mentioned.
Also, search in Google for your case that AlarmManager doesn't work when device is locked. You will find quite a lot of such issues both very old ones and more or less fresh.
AndroidAlarmManager.periodic doesn't work ... at all
AndroidAlarmManager.periodic doesn't work ... at all
It would be much helper if you could share more tech information on how do use, where you test, etc. Better to open a new issue and describe.
I can tell you that periodic works as of last version of AndroidAlarmManager as I tested it on multiple devices last week.
Till we have valid information about usage and sample to reproduce we can't help you.
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days