Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomeWidget.registerInteractivityCallback NOT working on Android after app is fully killed #318

Open
1 task
HadesPTIT opened this issue Nov 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@HadesPTIT
Copy link

What happened?

I am using registerInteractivityCallback to call Dart code from a widget, just only increment count sample.
On iOS, the callback works perfectly, even when the app is not running.
However, on Android, the callback does not work if the app has been killed. Only running in the background.
I'm working on: home_widget: 0.5.0

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // Set AppGroup Id. This is needed for iOS Apps to talk to their WidgetExtensions
  await HomeWidget.setAppGroupId('group.com.example.homeWidgetReminder');
  // Register an Interactivity Callback. It is necessary that this method is static and public
  await HomeWidget.registerInteractivityCallback(interactiveCallback);
  runApp(const MyApp());
}

/// Callback invoked by HomeWidget Plugin when performing interactive actions
/// The @pragma('vm:entry-point') Notification is required so that the Plugin can find it
@pragma('vm:entry-point')
Future<void> interactiveCallback(Uri? uri) async {
  // Set AppGroup Id. This is needed for iOS Apps to talk to their WidgetExtensions
  await HomeWidget.setAppGroupId('group.com.example.homeWidgetReminder');

  // We check the host of the uri to determine which action should be triggered.
  if (uri?.host == 'increment') {
    await _increment();
  } else if (uri?.host == 'clear') {
    await _clear();
  }
}

const _countKey = 'counter';

/// Gets the currently stored Value
Future<int> get _value async {
  final value = await HomeWidget.getWidgetData<int>(_countKey, defaultValue: 0);
  return value!;
}

/// Retrieves the current stored value
/// Increments it by one
/// Saves that new value
/// @returns the new saved value
Future<int> _increment() async {
  final oldValue = await _value;
  final newValue = oldValue + 1;
  await _sendAndUpdate(newValue);
  return newValue;
}

What do you expect?

Expect worked on Android even when app being killed

Relevant log output

No response

Execute in a terminal and put output into the code block below

Output of: flutter doctor -v

On which Platform do you experience this issue?

Android

Other information

No response

Are you interested in working on a PR for this?

  • I want to work on this
@HadesPTIT HadesPTIT added the bug Something isn't working label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant