active_package 0.0.1 copy "active_package: ^0.0.1" to clipboard
active_package: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin that helps you know the package name of any application running in foreground (Android only).

active_package #

A Flutter plugin that helps you know the package name of any application running in foreground.

When it can be used #

  • Know which app is opened in foreground while your app is running in background.
  • Get the package name of your main app.

Getting Started #

Check the example folder for a complete working example about the plugin


Future<void> getPackageName() async {
  String packageName;
  // Platform messages may fail, so we use a try/catch PlatformException.
  // We also handle the message potentially returning null.
  try {
    packageName = await _activePackagePlugin.getActivePackageName() ??
        'Unknown package name';
  } on PlatformException {
    packageName = 'Failed to get the active package name.';
  }

  // If the widget was removed from the tree while the asynchronous platform
  // message was in flight, we want to discard the reply rather than calling
  // setState to update our non-existent appearance.
  if (!mounted) return;

  setState(() {
    _packageName = packageName;
  });
}

1
likes
120
pub points
11%
popularity

Publisher

unverified uploader

A Flutter plugin that helps you know the package name of any application running in foreground (Android only).

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on active_package