Bug 1407961 - Show home after creating PWA. draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 12 Oct 2017 18:48:21 +0800
changeset 679045 3aa4953d265e5f4afd0e609933c577695c26071b
parent 678461 d1b3738b7ee93aa0d023242a6726b7744fbbc8ff
child 735525 d652094b8f0074540f48808a4274d4737f319046
push id84136
push userbmo:cnevinchen@gmail.com
push dateThu, 12 Oct 2017 10:48:58 +0000
bugs1407961
milestone58.0a1
Bug 1407961 - Show home after creating PWA. MozReview-Commit-ID: DM2nvjFrges
mobile/android/base/java/org/mozilla/gecko/util/ShortcutUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/util/ShortcutUtils.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/ShortcutUtils.java
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.util;
 
 import android.annotation.TargetApi;
+import android.app.PendingIntent;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentSender;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.drawable.Icon;
 import android.graphics.Color;
 import android.graphics.Paint;
@@ -84,20 +85,25 @@ public class ShortcutUtils {
                 .invoke(builder, shortcutIntent);
 
             builderCls.getDeclaredMethod("setShortLabel", CharSequence.class)
                 .invoke(builder, aTitle != null ? aTitle : aURI);
 
             Object info = builderCls.getDeclaredMethod("build")
                 .invoke(builder);
 
+            final Intent intent = new Intent(Intent.ACTION_MAIN);
+            intent.addCategory(Intent.CATEGORY_HOME);
+            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
+            final IntentSender intentSender = pendingIntent.getIntentSender();
             mgrCls.getDeclaredMethod("requestPinShortcut",
                                      info.getClass(),
                                      IntentSender.class)
-                .invoke(mgr, info, null);
+                .invoke(mgr, info, intentSender);
         } catch (Exception e) {
             Log.e(LOG_TAG, "Failed to pin shortcut: ", e);
         }
 
         // Use this when we can build against SDK 26
         //
         // final ShortcutManager mgr = context.getSystemService(ShortcutManager.class);