startBackgroundService method

Future<bool> startBackgroundService()

Implementation

Future<bool> startBackgroundService() async {
  try {
    if (defaultTargetPlatform != TargetPlatform.android) {
      return false;
    }
    if (!(await isBackgroundServiceRunning)) {
      final CallbackHandle? bgHandle = PluginUtilities.getCallbackHandle(_callBackDispatcher);
      debugPrint("pluginCallbackHandle flutter side ${bgHandle?.toRawHandle()}");
      final success = await Untitled.Untitled_Constants.methodChannel.invokeMethod(UntitledStrings.startBackgroundServiceMethodName, {
        "pluginCallbackHandle": bgHandle?.toRawHandle(),
      });
      debugPrint("startBackgroundService called $success");
      return success;
    }
    return false;
  } on Exception {
    return false;
  }
}