flutter_background_fetch icon indicating copy to clipboard operation
flutter_background_fetch copied to clipboard

Android _onBackgroundFetch failed to trigger continuously after every 15 minutes

Open siraj-logicvalley opened this issue 3 years ago • 1 comments

Your Environment

  • Plugin version: background_fetch: ^1.0.3
  • Platform: Android
  • OS version: Oreo
  • Device manufacturer / model: Moto G5 plus
  • Flutter info : (2.5.3)

I have added new entry to event log table when onBackground fetch trigger with dateTime. Smoothly it worked for some hour. but failed to continuously trigger after every 15 minutes. please review the screenshot ( it triggered from 18:43:33 to 20:15:11 )

Future initPlatformState() async { // Configure BackgroundFetch. try { var json = await read(IS_BG_FETCH_STARTED_KEY); if (json == null || json == "0") { var status = await BackgroundFetch.configure( BackgroundFetchConfig( minimumFetchInterval: 15, forceAlarmManager: true, stopOnTerminate: false, startOnBoot: true, enableHeadless: true, requiresBatteryNotLow: false, requiresCharging: false, requiresStorageNotLow: false, requiresDeviceIdle: false, requiredNetworkType: NetworkType.ANY, ), _onBackgroundFetch, _onBackgroundFetchTimeout);

print('[BackgroundFetch] configure success: $status');

doStoreEventLog( "Init Platform", "check background fetch configured or not " + DateTime.fromMillisecondsSinceEpoch( DateTime.now().millisecondsSinceEpoch) .toString());

int timestamp = DateTime.now().millisecondsSinceEpoch;

if (status == BackgroundFetch.STATUS_AVAILABLE) { doStoreEventLog( "Init Platform", DateTime.fromMillisecondsSinceEpoch(timestamp).toString() + " - " + "Background fetch configured successfully");

write( NEXT_BG_FETCH_DATE_TIME_KEY, (DateTime.now().millisecondsSinceEpoch + (1000 * 60 * 15)) .toString());

write(IS_BG_FETCH_STARTED_KEY, "1");

} else {

doStoreEventLog( "Init Platform", DateTime.fromMillisecondsSinceEpoch(timestamp).toString() + " - " + "Background fetch configuration failed " + " - " + "Status code" + status.toString()); }

} else { print('[BackgroundFetch] already configured '); int timestamp = DateTime.now().millisecondsSinceEpoch; doStoreEventLog( "Init Platform", DateTime.fromMillisecondsSinceEpoch(timestamp).toString() + " - " + "[BackgroundFetch] already configured"); } } on Exception catch (e) { print("[BackgroundFetch] configure ERROR: $e"); int timestamp = DateTime.now().millisecondsSinceEpoch; doStoreEventLog( "Init Platform", DateTime.fromMillisecondsSinceEpoch(timestamp).toString() + "|" + "[BackgroundFetch] configure ERROR: $e"); }

}

Future doStoreEventLog(String title, String body) async { var box = await Hive.openLazyBox('notificationBox'); DateTime now = DateTime.now(); String dateTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);

EventLog eventLog = EventLog(title: title, body: body, dateTime: dateTime, isDelete: false);

await box.add(eventLog); }

void write(String key, dynamic value) { GetStorage().write(key, value); }

Future<String> read(String key) async{ return await GetStorage().read(key); } Screenshot_20220304-223627 1

How to restart the background fetch if not working after long period of time? can i get any log history of Background fetch callback

siraj-logicvalley avatar Mar 04 '22 17:03 siraj-logicvalley

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

stale[bot] avatar Jun 12 '22 20:06 stale[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Apr 18 '24 01:04 github-actions[bot]