static_shortcuts 0.0.2 copy "static_shortcuts: ^0.0.2" to clipboard
static_shortcuts: ^0.0.2 copied to clipboard

PlatformAndroid

Generate and handle static shortcuts for Android and access the intent in one line of dart code.

Generate and handle static shortcuts for Android. They can trigger custom actions inside of your app.

[GIF]

Getting Started #

Modify the AndroidManifest.xml #

Go to android/app/src/main/AndroidManifest.xml and add the following lines:

<manifest>
    <application>
        <activity>
            <meta-data
              android:name="android.app.shortcuts"
              android:resource="@xml/shortcuts"
            />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

Dependency #

Add your launcher_name configuration to your pubspec.yaml as shown below. For each shortcut, you have to define the intent, that is accessible from within your app, a targetClass and a targetPackage, which help to identify the main Kotlin or Java file of your project, and a label, which will be visible for the user.

dependencies: 
  static_shortcuts: ^0.0.1 # check the latest version on pub.dev

# define your shortcuts here
static_shortcuts:
  foo:
    icon: "assets/add_icon.png"
    intent: "foo"
    targetClass: "com.OJCreator.static_shortcuts.MainActivity"
    targetPackage: "com.OJCreator.static_shortcuts"
    label: "Foo"
  bar:
    intent: "bar"
    targetClass: "com.OJCreator.static_shortcuts.MainActivity"
    targetPackage: "com.OJCreator.static_shortcuts"
    label: "Bar"

When you specified your shortcuts, run dart run static_shortcuts in your console.

Access the intent #

You can access the intent at any moment, that has been used to launch the app:

import 'package:static_shortcuts/static_shortcuts.dart';

final shortcut = await StaticShortcuts.getShortcutIntentUri();

Localization #

You can localize the launcher name like this:

static_shortcuts:
  foo:
    icon: "assets/add_icon.png"
    intent: "foo"
    targetClass: "com.OJCreator.static_shortcuts.MainActivity"
    targetPackage: "com.OJCreator.static_shortcuts"
    label:
      default: "Default (English) foo"
      de: "German foo"
      fr: "French foo"
      es: "Spanish foo"
      [...]

But make sure to add a default language for users, that do not use one of the other specified languages.

1
likes
160
points
47
downloads

Publisher

unverified uploader

Weekly Downloads

Generate and handle static shortcuts for Android and access the intent in one line of dart code.

Homepage

Documentation

API reference

License

BSD-2-Clause (license)

Dependencies

flutter, image, path, path_provider, plugin_platform_interface, xml, yaml

More

Packages that depend on static_shortcuts