Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser; | |
| 6 | |
| 7 import android.app.Activity; | |
| 8 import android.content.Intent; | |
| 9 import android.content.pm.PackageManager; | |
| 10 import android.content.pm.ResolveInfo; | |
| 11 import android.net.Uri; | |
| 12 import android.os.AsyncTask; | |
| 13 | |
| 14 import org.chromium.base.BuildInfo; | |
| 15 import org.chromium.chrome.R; | |
| 16 | |
| 17 import java.util.concurrent.ExecutionException; | |
| 18 | |
| 19 /** | |
| 20 * A utility class for querying information about the default browser setting. | |
| 21 */ | |
| 22 public class DefaultBrowserInfo { | |
| 23 private static final String SAMPLE_URL = "https://www.google.com"; | |
|
Ted C
2017/02/14 19:02:00
I would use the one from cacheIsChromeDefaultBrows
ltian
2017/02/16 05:05:10
Done.
| |
| 24 | |
| 25 /** | |
| 26 * @return Title of menu item for opening tab in the default browser. | |
| 27 * @param activity The activity to open the menu. | |
| 28 * @param isOpenedByChrome Whether the menu is opened by Chrome. | |
| 29 * @throws ExecutionException | |
| 30 * @throws InterruptedException | |
| 31 */ | |
| 32 public static String getTitleOpenInDefaultBrowser(final Activity activity, | |
| 33 final Boolean isOpenedByChrome) throws InterruptedException, Executi onException { | |
|
Ted C
2017/02/14 19:02:00
Why capital B boolean?
Also, do you need Activity
ltian
2017/02/16 05:05:10
Done.
| |
| 34 AsyncTask<Void, Void, String> defaultBrowserFetcher = new AsyncTask<Void , Void, String>() { | |
|
Ted C
2017/02/14 19:02:00
Creating an AsyncTask and then calling get on it i
| |
| 35 @Override | |
| 36 protected String doInBackground(Void... params) { | |
| 37 String packageLabel = null; | |
| 38 if (isOpenedByChrome) { | |
| 39 // If the Custom Tab was created by Chrome, Chrome should op en it. | |
| 40 packageLabel = BuildInfo.getPackageLabel(activity); | |
| 41 } else { | |
| 42 // Check if there is a default handler for the Intent. If s o, grab its label. | |
| 43 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SAM PLE_URL)); | |
| 44 PackageManager pm = activity.getPackageManager(); | |
| 45 ResolveInfo info = pm.resolveActivity(intent, 0); | |
| 46 if (info != null && info.match != 0) { | |
| 47 packageLabel = info.loadLabel(pm).toString(); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 return packageLabel == null | |
| 52 ? activity.getString(R.string.menu_open_in_product_defau lt) | |
| 53 : activity.getString(R.string.menu_open_in_product, pack ageLabel); | |
| 54 } | |
| 55 }; | |
| 56 defaultBrowserFetcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
| 57 return defaultBrowserFetcher.get(); | |
| 58 } | |
| 59 } | |
| OLD | NEW |