plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Question]: Repeat every 10 seconds not working

Open mojtabamn22 opened this issue 2 years ago • 7 comments

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

mojtabamn22 avatar Jun 07 '22 19:06 mojtabamn22

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.

miquelbeltran avatar Jun 08 '22 04:06 miquelbeltran

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.

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"/>

<activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">

   <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

mojtabamn22 avatar Jun 08 '22 17:06 mojtabamn22

I think it is related to https://github.com/fluttercommunity/plus_plugins/pull/810 and should be fixed in next release

vbuberen avatar Jun 19 '22 20:06 vbuberen

I think it is related to #810 and should be fixed in next release

But it does not work when the phone is locked

mojtabamn22 avatar Jun 20 '22 16:06 mojtabamn22

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.

vbuberen avatar Jun 21 '22 10:06 vbuberen

AndroidAlarmManager.periodic doesn't work ... at all

carman247 avatar Jun 23 '22 08:06 carman247

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.

vbuberen avatar Jun 25 '22 08:06 vbuberen

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

github-actions[bot] avatar Sep 24 '22 00:09 github-actions[bot]

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

github-actions[bot] avatar Dec 29 '22 00:12 github-actions[bot]