2626@ SuppressWarnings ("unchecked" )
2727public class QuickActionsPlugin implements MethodCallHandler {
2828 private final Registrar registrar ;
29+ private static final String intentExtraAction = "action" ;
30+ private static String launchAction = null ;
2931
3032 // Channel is a static field because it needs to be accessible to the
3133 // {@link ShortcutHandlerActivity} which has to be a static class with
@@ -45,6 +47,7 @@ private QuickActionsPlugin(Registrar registrar) {
4547 public static void registerWith (Registrar registrar ) {
4648 channel = new MethodChannel (registrar .messenger (), "plugins.flutter.io/quick_actions" );
4749 channel .setMethodCallHandler (new QuickActionsPlugin (registrar ));
50+ launchAction = registrar .activity ().getIntent ().getStringExtra (intentExtraAction );
4851 }
4952
5053 @ Override
@@ -68,6 +71,10 @@ public void onMethodCall(MethodCall call, Result result) {
6871 case "clearShortcutItems" :
6972 shortcutManager .removeAllDynamicShortcuts ();
7073 break ;
74+ case "getLaunchAction" :
75+ result .success (launchAction );
76+ launchAction = null ;
77+ return ;
7178 default :
7279 result .notImplemented ();
7380 return ;
@@ -117,8 +124,27 @@ protected void onCreate(Bundle savedInstanceState) {
117124 String type = intent .getStringExtra ("type" );
118125 if (channel != null ) {
119126 channel .invokeMethod ("launch" , type );
127+ } else {
128+ startActivity (getIntentToOpenMainActivity (this , type ));
120129 }
121130 finish ();
122131 }
132+
133+ /**
134+ * Returns Intent to launch the MainActivity. Used to start the app, if one of quick actions was
135+ * called from the background.
136+ */
137+ private Intent getIntentToOpenMainActivity (Context context , String type ) {
138+ Intent launchIntentForPackage =
139+ context
140+ .getPackageManager ()
141+ .getLaunchIntentForPackage (context .getApplicationContext ().getPackageName ());
142+ if (launchIntentForPackage == null ) {
143+ return null ;
144+ } else {
145+ launchIntentForPackage .putExtra (intentExtraAction , type );
146+ return launchIntentForPackage ;
147+ }
148+ }
123149 }
124150}
0 commit comments