Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: customtabs/src/android/support/customtabs/browseractions/BrowserActionsIntent.java

Issue 2961203002: Support library changes to allow a callback notifying the selection of default items for Browser Ac… (Closed)
Patch Set: Update based on Yusuf's comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2017 The Android Open Source Project 2 * Copyright (C) 2017 The Android Open Source Project
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at 6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, 11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 package android.support.customtabs.browseractions; 16 package android.support.customtabs.browseractions;
17 17
18 import android.app.PendingIntent; 18 import android.app.PendingIntent;
19 import android.content.Context; 19 import android.content.Context;
20 import android.content.Intent; 20 import android.content.Intent;
21 import android.content.pm.PackageManager; 21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo; 22 import android.content.pm.ResolveInfo;
23 import android.graphics.Bitmap;
23 import android.net.Uri; 24 import android.net.Uri;
24 import android.os.Build; 25 import android.os.Build;
25 import android.os.Bundle; 26 import android.os.Bundle;
26 import android.support.annotation.IntDef; 27 import android.support.annotation.IntDef;
27 import android.support.annotation.NonNull; 28 import android.support.annotation.NonNull;
29 import android.support.customtabs.CustomTabsClient;
28 import android.support.customtabs.CustomTabsIntent; 30 import android.support.customtabs.CustomTabsIntent;
29 import android.support.customtabs.CustomTabsSession; 31 import android.support.customtabs.CustomTabsSession;
30 import android.support.v4.content.ContextCompat; 32 import android.support.v4.content.ContextCompat;
33 import android.util.Log;
31 34
32 import java.lang.annotation.Retention; 35 import java.lang.annotation.Retention;
33 import java.lang.annotation.RetentionPolicy; 36 import java.lang.annotation.RetentionPolicy;
34 import java.util.ArrayList; 37 import java.util.ArrayList;
35 import java.util.List; 38 import java.util.List;
36 39
37 /** 40 /**
38 * Class holding the {@link Intent} and start bundle for a Browser Actions Activ ity. 41 * Class holding the {@link Intent} and start bundle for a Browser Actions Activ ity.
39 * 42 *
40 * <p> 43 * <p>
41 * <strong>Note:</strong> The constants below are public for the browser impleme ntation's benefit. 44 * <strong>Note:</strong> The constants below are public for the browser impleme ntation's benefit.
42 * You are strongly encouraged to use {@link BrowserActionsIntent.Builder}.</p> 45 * You are strongly encouraged to use {@link BrowserActionsIntent.Builder}.</p>
43 */ 46 */
44 public class BrowserActionsIntent { 47 public class BrowserActionsIntent {
48 private final static String TAG = "BrowserActions";
45 private final static String TEST_URL = "https://www.example.com"; 49 private final static String TEST_URL = "https://www.example.com";
46 50
47 /** 51 /**
48 * Extra that specifies {@link PendingIntent} indicating which Application s ends the {@link 52 * Extra that specifies {@link PendingIntent} indicating which Application s ends the {@link
49 * BrowserActionsIntent}. 53 * BrowserActionsIntent}.
50 */ 54 */
51 public final static String EXTRA_APP_ID = "android.support.customtabs.browse ractions.APP_ID"; 55 public final static String EXTRA_APP_ID = "android.support.customtabs.browse ractions.APP_ID";
52 56
53 /** 57 /**
54 * Indicates that the user explicitly opted out of Browser Actions in the ca lling application. 58 * Indicates that the user explicitly opted out of Browser Actions in the ca lling application.
(...skipping 22 matching lines...) Expand all
77 */ 81 */
78 public static final String EXTRA_TYPE = "android.support.customtabs.browsera ctions.extra.TYPE"; 82 public static final String EXTRA_TYPE = "android.support.customtabs.browsera ctions.extra.TYPE";
79 83
80 /** 84 /**
81 * Extra that specifies List<Bundle> used for adding custom items to the Bro wser Actions menu. 85 * Extra that specifies List<Bundle> used for adding custom items to the Bro wser Actions menu.
82 */ 86 */
83 public static final String EXTRA_MENU_ITEMS = 87 public static final String EXTRA_MENU_ITEMS =
84 "android.support.customtabs.browseractions.extra.MENU_ITEMS"; 88 "android.support.customtabs.browseractions.extra.MENU_ITEMS";
85 89
86 /** 90 /**
91 * Extra that specifies the PendingIntent to be launched when a browser spec ified menu item is
92 * selected. The id of the chosen item will be notified through the data of its Intent.
93 */
94 public static final String EXTRA_SELECTED_ACTION_PENDING_INTENT =
95 "android.support.customtabs.browseractions.extra.SELECTED_ACTION_PEN DING_INTENT";
96
97 /**
87 * The maximum allowed number of custom items. 98 * The maximum allowed number of custom items.
88 */ 99 */
89 public static final int MAX_CUSTOM_ITEMS = 5; 100 public static final int MAX_CUSTOM_ITEMS = 5;
90 101
91 /** 102 /**
92 * Defines the types of url for Browser Actions menu. 103 * Defines the types of url for Browser Actions menu.
93 */ 104 */
94 @IntDef({URL_TYPE_NONE, URL_TYPE_IMAGE, URL_TYPE_VIDEO, URL_TYPE_AUDIO, URL_ TYPE_FILE, 105 @IntDef({URL_TYPE_NONE, URL_TYPE_IMAGE, URL_TYPE_VIDEO, URL_TYPE_AUDIO, URL_ TYPE_FILE,
95 URL_TYPE_PLUGIN}) 106 URL_TYPE_PLUGIN})
96 @Retention(RetentionPolicy.SOURCE) 107 @Retention(RetentionPolicy.SOURCE)
97 public @interface BrowserActionsUrlType {} 108 public @interface BrowserActionsUrlType {}
98 public static final int URL_TYPE_NONE = 0; 109 public static final int URL_TYPE_NONE = 0;
99 public static final int URL_TYPE_IMAGE = 1; 110 public static final int URL_TYPE_IMAGE = 1;
100 public static final int URL_TYPE_VIDEO = 2; 111 public static final int URL_TYPE_VIDEO = 2;
101 public static final int URL_TYPE_AUDIO = 3; 112 public static final int URL_TYPE_AUDIO = 3;
102 public static final int URL_TYPE_FILE = 4; 113 public static final int URL_TYPE_FILE = 4;
103 public static final int URL_TYPE_PLUGIN = 5; 114 public static final int URL_TYPE_PLUGIN = 5;
104 115
105 /** 116 /**
117 * Defines the the ids of the browser specified menu items in Browser Action s.
118 * TODO(ltian): A long term solution need, since other providers might have customized menus.
119 */
120 @IntDef({ITEM_INVALID_ITEM, ITEM_OPEN_IN_NEW_TAB, ITEM_OPEN_IN_INCOGNITO, IT EM_DOWNLOAD,
121 ITEM_COPY, ITEM_SHARE})
122 @Retention(RetentionPolicy.SOURCE)
123 public @interface BrowserActionsItemId {}
124 public static final int ITEM_INVALID_ITEM = -1;
125 public static final int ITEM_OPEN_IN_NEW_TAB = 0;
126 public static final int ITEM_OPEN_IN_INCOGNITO = 1;
127 public static final int ITEM_DOWNLOAD = 2;
128 public static final int ITEM_COPY = 3;
129 public static final int ITEM_SHARE = 4;
130
131 /**
106 * An {@link Intent} used to start the Browser Actions Activity. 132 * An {@link Intent} used to start the Browser Actions Activity.
107 */ 133 */
108 private final Intent mIntent; 134 public final Intent mIntent;
109 135
110 /** 136 /**
111 * Gets the Intent of {@link BrowserActionsIntent}. 137 * Gets the Intent of {@link BrowserActionsIntent}.
112 * @return the Intent of {@link BrowserActionsIntent}. 138 * @return the Intent of {@link BrowserActionsIntent}.
113 */ 139 */
114 public Intent getIntent() { 140 public Intent getIntent() {
115 return mIntent; 141 return mIntent;
116 } 142 }
117 143
118 private BrowserActionsIntent(@NonNull Intent intent) { 144 private BrowserActionsIntent(@NonNull Intent intent) {
119 this.mIntent = intent; 145 this.mIntent = intent;
120 } 146 }
121 147
122 /** 148 /**
123 * Builder class for opening a Browser Actions context menu. 149 * Builder class for opening a Browser Actions context menu.
124 */ 150 */
125 public static final class Builder { 151 public static final class Builder {
126 private final Intent mIntent = new Intent(BrowserActionsIntent.ACTION_BR OWSER_ACTIONS_OPEN); 152 private final Intent mIntent = new Intent(BrowserActionsIntent.ACTION_BR OWSER_ACTIONS_OPEN);
127 private Context mContext; 153 private Context mContext;
128 private Uri mUri; 154 private Uri mUri;
129 @BrowserActionsUrlType 155 @BrowserActionsUrlType
130 private int mType; 156 private int mType;
131 private ArrayList<Bundle> mMenuItems = null; 157 private ArrayList<Bundle> mMenuItems = null;
158 private PendingIntent mOnItemSelectedPendingIntent = null;
132 159
133 /** 160 /**
134 * Constructs a {@link BrowserActionsIntent.Builder} object associated w ith default setting 161 * Constructs a {@link BrowserActionsIntent.Builder} object associated w ith default setting
135 * for a selected url. 162 * for a selected url.
136 * @param context The context requesting the Browser Actions context men u. 163 * @param context The context requesting the Browser Actions context men u.
137 * @param uri The selected url for Browser Actions menu. 164 * @param uri The selected url for Browser Actions menu.
138 */ 165 */
139 public Builder(Context context, Uri uri) { 166 public Builder(Context context, Uri uri) {
140 mContext = context; 167 mContext = context;
141 mUri = uri; 168 mUri = uri;
(...skipping 15 matching lines...) Expand all
157 * Only maximum {@link BrowserActionsIntent.MAX_CUSTOM_ITEMS} custom ite ms are allowed, 184 * Only maximum {@link BrowserActionsIntent.MAX_CUSTOM_ITEMS} custom ite ms are allowed,
158 * otherwise throws an {@link IllegalStateException}. 185 * otherwise throws an {@link IllegalStateException}.
159 * @param items The list of {@link BrowserActionItem} for custom items. 186 * @param items The list of {@link BrowserActionItem} for custom items.
160 */ 187 */
161 public Builder setCustomItems(ArrayList<BrowserActionItem> items) { 188 public Builder setCustomItems(ArrayList<BrowserActionItem> items) {
162 if (items.size() >= MAX_CUSTOM_ITEMS) { 189 if (items.size() >= MAX_CUSTOM_ITEMS) {
163 throw new IllegalStateException( 190 throw new IllegalStateException(
164 "Exceeded maximum toolbar item count of " + MAX_CUSTOM_I TEMS); 191 "Exceeded maximum toolbar item count of " + MAX_CUSTOM_I TEMS);
165 } 192 }
166 for (int i = 0; i < items.size(); i++) { 193 for (int i = 0; i < items.size(); i++) {
167 mMenuItems.add(getBundleFromItem(items.get(i))); 194 if (items.get(i).getTitle() == null) {
195 throw new IllegalArgumentException("Custom item title is nul l");
196 } else if (items.get(i).getAction() == null) {
197 throw new IllegalArgumentException("Custom item action is nu ll");
198 } else {
199 mMenuItems.add(getBundleFromItem(items.get(i)));
200 }
168 } 201 }
169 return this; 202 return this;
170 } 203 }
171 204
172 /** 205 /**
206 * Set the PendingIntent to be launched when a a browser specified menu item is selected.
207 * @param onItemSelectedPendingIntent The PendingIntent to be launched.
208 */
209 public Builder setOnItemSelectedAction(PendingIntent onItemSelectedPendi ngIntent) {
210 mOnItemSelectedPendingIntent = onItemSelectedPendingIntent;
211 return this;
212 }
213
214 /**
173 * Populates a {@link Bundle} to hold a custom item for Browser Actions menu. 215 * Populates a {@link Bundle} to hold a custom item for Browser Actions menu.
174 * @param item A custom item for Browser Actions menu. 216 * @param item A custom item for Browser Actions menu.
175 * @return The Bundle of custom item. 217 * @return The Bundle of custom item.
176 */ 218 */
177 private Bundle getBundleFromItem(BrowserActionItem item) { 219 private Bundle getBundleFromItem(BrowserActionItem item) {
178 Bundle bundle = new Bundle(); 220 Bundle bundle = new Bundle();
179 bundle.putString(KEY_TITLE, item.getTitle()); 221 bundle.putString(KEY_TITLE, item.getTitle());
180 bundle.putParcelable(KEY_ACTION, item.getAction()); 222 bundle.putParcelable(KEY_ACTION, item.getAction());
181 if (item.getIcon() != null) bundle.putParcelable(KEY_ICON, item.getI con()); 223 if (item.getIcon() != null) bundle.putParcelable(KEY_ICON, item.getI con());
182 return bundle; 224 return bundle;
183 } 225 }
184 226
185 /** 227 /**
186 * Combines all the options that have been set and returns a new {@link 228 * Combines all the options that have been set and returns a new {@link
187 * BrowserActionsIntent} object. 229 * BrowserActionsIntent} object.
188 */ 230 */
189 public BrowserActionsIntent build() { 231 public BrowserActionsIntent build() {
190 mIntent.setData(mUri); 232 mIntent.setData(mUri);
191 mIntent.putExtra(EXTRA_TYPE, mType); 233 mIntent.putExtra(EXTRA_TYPE, mType);
192 mIntent.putParcelableArrayListExtra(EXTRA_MENU_ITEMS, mMenuItems); 234 mIntent.putParcelableArrayListExtra(EXTRA_MENU_ITEMS, mMenuItems);
193 PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0); 235 PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(), 0);
194 mIntent.putExtra(EXTRA_APP_ID, pendingIntent); 236 mIntent.putExtra(EXTRA_APP_ID, pendingIntent);
237 mIntent.putExtra(EXTRA_SELECTED_ACTION_PENDING_INTENT, mOnItemSelect edPendingIntent);
195 return new BrowserActionsIntent(mIntent); 238 return new BrowserActionsIntent(mIntent);
196 } 239 }
197 } 240 }
198 241
199 /** 242 /**
200 * Open a Browser Actions menu with default settings. 243 * Construct a BrowserActionsIntent with default settings and launch it to o pen a Browser
201 * It first checks if any Browser Actions provider is available to create a context menu. 244 * Actions menu.
202 * If not, open a Browser Actions menu locally from support library.
203 * @param context The context requesting for a Browser Actions menu. 245 * @param context The context requesting for a Browser Actions menu.
204 * @param uri The url for Browser Actions menu. 246 * @param uri The url for Browser Actions menu.
205 */ 247 */
206 public static void openBrowserAction(Context context, Uri uri) { 248 public static void openBrowserAction(Context context, Uri uri) {
207 if (hasBrowserActionsIntentHandler(context)) { 249 BrowserActionsIntent intent = new BrowserActionsIntent.Builder(context, uri).build();
208 BrowserActionsIntent intent = new BrowserActionsIntent.Builder(conte xt, uri).build(); 250 launchIntent(context, intent.getIntent());
209 ContextCompat.startActivity(context, intent.getIntent(), null);
210 } else {
211 openFallbackBrowserActionsMenu(
212 context, uri, URL_TYPE_NONE, new ArrayList<BrowserActionItem >());
213 }
214 } 251 }
215 252
216 /** 253 /**
217 * Open a Browser Actions menu with custom items. 254 * Construct a BrowserActionsIntent with custom settings and launch it to op en a Browser Actions
218 * It first checks if any Browser Actions provider is available to create a context menu. 255 * menu.
219 * If not, open a Browser Actions menu locally from support library.
220 * @param context The context requesting for a Browser Actions menu. 256 * @param context The context requesting for a Browser Actions menu.
221 * @param uri The url for Browser Actions menu. 257 * @param uri The url for Browser Actions menu.
222 * @param type The type of the url for context menu to be opened. 258 * @param type The type of the url for context menu to be opened.
223 * @param items List of custom items to be added to Browser Actions menu. 259 * @param items List of custom items to be added to Browser Actions menu.
260 * @param pendingIntent The PendingIntent to be launched when a browser spec ified menu item is
261 * selected. The browser will perform the PendingIntent so this should only go to a {@link
262 * BroadcastReceiver}.
224 */ 263 */
225 public static void openBrowserAction( 264 public static void openBrowserAction(Context context, Uri uri, int type,
226 Context context, Uri uri, int type, ArrayList<BrowserActionItem> ite ms) { 265 ArrayList<BrowserActionItem> items, PendingIntent pendingIntent) {
227 if (hasBrowserActionsIntentHandler(context)) { 266 BrowserActionsIntent intent = new BrowserActionsIntent.Builder(context, uri)
228 BrowserActionsIntent intent = new BrowserActionsIntent.Builder(conte xt, uri) 267 .setUrlType(type)
229 .setUrlType(type) 268 .setCustomItems(items)
230 .setCustomItems(items) 269 .setOnItemSelectedAction(pendingIn tent)
231 .build(); 270 .build();
232 ContextCompat.startActivity(context, intent.getIntent(), null); 271 launchIntent(context, intent.getIntent());
233 } else {
234 openFallbackBrowserActionsMenu(context, uri, type, items);
235 }
236 } 272 }
237 273
238 /** 274 /**
239 * Check whether any Browser Actions provider is available to handle the {@l ink 275 * Launch an Intent to open a Browser Actions menu.
276 * It first checks if any Browser Actions provider is available to create th e menu.
277 * If the default Browser supports Browser Actions, menu will be opened by t he default Browser,
278 * otherwise show a intent picker.
279 * If not provider, a Browser Actions menu is opened locally from support li brary.
280 * @param context The context requesting for a Browser Actions menu.
281 * @param intent The {@link Intent} holds the setting for Browser Actions me nu.
282 */
283 public static void launchIntent(Context context, Intent intent) {
284 List<ResolveInfo> handlers = getBrowserActionsIntentHandlers(context);
285 if (handlers == null || handlers.size() == 0) {
286 openFallbackBrowserActionsMenu(context, intent);
287 return;
288 } else if (handlers.size() == 1) {
289 intent.setPackage(handlers.get(0).activityInfo.packageName);
290 } else {
291 Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_UR L));
292 PackageManager pm = context.getPackageManager();
293 ResolveInfo defaultHandler =
294 pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ ONLY);
295 if (defaultHandler != null) {
296 String defaultPackageName = defaultHandler.activityInfo.packageN ame;
297 for (int i = 0; i < handlers.size(); i++) {
298 if (defaultPackageName.equals(handlers.get(i).activityInfo.p ackageName)) {
299 intent.setPackage(defaultPackageName);
300 break;
301 }
302 }
303 }
304 }
305 ContextCompat.startActivity(context, intent, null);
306 }
307
308 /**
309 * Returns a list of Browser Actions providers available to handle the {@lin k
240 * BrowserActionsIntent}. 310 * BrowserActionsIntent}.
241 * @param context The context requesting for a Browser Actions menu. 311 * @param context The context requesting for a Browser Actions menu.
242 * @return true If a Browser Actions provider is available handle the intent . 312 * @return List of Browser Actions providers available to handle the intent.
243 */ 313 */
244 private static boolean hasBrowserActionsIntentHandler(Context context) { 314 private static List<ResolveInfo> getBrowserActionsIntentHandlers(Context con text) {
245 Intent intent = 315 Intent intent =
246 new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN, Uri .parse(TEST_URL)); 316 new Intent(BrowserActionsIntent.ACTION_BROWSER_ACTIONS_OPEN, Uri .parse(TEST_URL));
247 PackageManager pm = context.getPackageManager(); 317 PackageManager pm = context.getPackageManager();
248 List<ResolveInfo> resolveInfoList = 318 return pm.queryIntentActivities(intent, PackageManager.MATCH_ALL);
249 pm.queryIntentActivities(intent, PackageManager.MATCH_ALL); 319 }
250 return resolveInfoList.size() > 0 ? true : false; 320
321 private static void openFallbackBrowserActionsMenu(
322 Context context, BrowserActionsIntent browserActionsIntent) {
323 openFallbackBrowserActionsMenu(context, browserActionsIntent.getIntent() );
324 }
325
326 private static void openFallbackBrowserActionsMenu(Context context, Intent i ntent) {
327 Uri uri = intent.getData();
328 int type = intent.getIntExtra(EXTRA_TYPE, URL_TYPE_NONE);
329 ArrayList<Bundle> bundles = intent.getParcelableArrayListExtra(EXTRA_MEN U_ITEMS);
330 List<BrowserActionItem> items = bundles != null ? parseBrowserActionItem s(bundles) : null;
331 openFallbackBrowserActionsMenu(context, uri, type, items);
251 } 332 }
252 333
253 /** 334 /**
254 * Open a Browser Actions menu from support library. 335 * Open a Browser Actions menu from support library.
255 * @param context The context requesting for a Browser Actions menu. 336 * @param context The context requesting for a Browser Actions menu.
256 * @param uri The url for Browser Actions menu. 337 * @param uri The url for Browser Actions menu.
257 * @param type The type of the url for context menu to be opened. 338 * @param type The type of the url for context menu to be opened.
258 * @param items List of custom items to add to Browser Actions menu. 339 * @param items List of custom items to add to Browser Actions menu.
259 */ 340 */
260 private static void openFallbackBrowserActionsMenu( 341 private static void openFallbackBrowserActionsMenu(
261 Context context, Uri uri, int type, ArrayList<BrowserActionItem> ite ms) { 342 Context context, Uri uri, int type, List<BrowserActionItem> items) {
262 return; 343 return;
263 } 344 }
264 345
265 /** 346 /**
347 * Gets custom item list for browser action menu.
348 * @param bundles Data for custom items from {@link BrowserActionsIntent}.
349 * @return List of {@link BrowserActionItem}
350 */
351 public static List<BrowserActionItem> parseBrowserActionItems(ArrayList<Bund le> bundles) {
352 List<BrowserActionItem> mActions = new ArrayList<>();
353 for (int i = 0; i < bundles.size(); i++) {
354 Bundle bundle = bundles.get(i);
355 String title = bundle.getString(BrowserActionsIntent.KEY_TITLE);
356 PendingIntent action = bundle.getParcelable(BrowserActionsIntent.KEY _ACTION);
357 Bitmap icon = bundle.getParcelable(BrowserActionsIntent.KEY_ICON);
358 if (title != null && action != null) {
359 BrowserActionItem item = new BrowserActionItem(title, action);
360 if (icon != null) {
361 item.setIcon(icon);
362 }
363 mActions.add(item);
364 } else if (title != null) {
365 throw new IllegalArgumentException("Missing action for item: " + i);
366 } else if (action != null) {
367 throw new IllegalArgumentException("Missing title for item: " + i);
368 } else {
369 throw new IllegalArgumentException("Missing title and action for item: " + i);
370 }
371 }
372 return mActions;
373 }
374
375 /**
266 * Get the package name of the creator application. 376 * Get the package name of the creator application.
267 * @param intent The {@link BrowserActionsIntent}. 377 * @param intent The {@link BrowserActionsIntent}.
268 * @return The creator package name. 378 * @return The creator package name.
269 */ 379 */
270 @SuppressWarnings("deprecation") 380 @SuppressWarnings("deprecation")
271 public static String getCreatorPackageName(Intent intent) { 381 public static String getCreatorPackageName(Intent intent) {
272 PendingIntent pendingIntent = intent.getParcelableExtra(BrowserActionsIn tent.EXTRA_APP_ID); 382 PendingIntent pendingIntent = intent.getParcelableExtra(BrowserActionsIn tent.EXTRA_APP_ID);
273 if (pendingIntent != null) { 383 if (pendingIntent != null) {
274 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { 384 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
275 return pendingIntent.getCreatorPackage(); 385 return pendingIntent.getCreatorPackage();
276 } else { 386 } else {
277 return pendingIntent.getTargetPackage(); 387 return pendingIntent.getTargetPackage();
278 } 388 }
279 } 389 }
280 return null; 390 return null;
281 } 391 }
282 } 392 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698