本文整理汇总了Java中android.support.customtabs.CustomTabsService类的典型用法代码示例。如果您正苦于以下问题:Java CustomTabsService类的具体用法?Java CustomTabsService怎么用?Java CustomTabsService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTabsService类属于android.support.customtabs包,在下文中一共展示了CustomTabsService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postMessage
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
/**
* Relay a postMessage request through the current channel assigned to this session.
* @param message The message to be sent.
* @return The result of the postMessage request. Returning true means the request was accepted,
* not necessarily that the postMessage was successful.
*/
public int postMessage(final String message) {
if (mChannel == null || !mChannel[0].isReady() || mChannel[0].isClosed()) {
return CustomTabsService.RESULT_FAILURE_MESSAGING_ERROR;
}
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
// It is still possible that the page has navigated while this task is in the queue.
// If that happens fail gracefully.
if (mChannel == null || mChannel[0].isClosed()) return;
mChannel[0].postMessage(message, null);
}
});
return CustomTabsService.RESULT_SUCCESS;
}
示例2: preconnectUrls
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
private boolean preconnectUrls(List<Bundle> likelyBundles) {
boolean atLeastOneUrl = false;
if (likelyBundles == null) return false;
WarmupManager warmupManager = WarmupManager.getInstance();
Profile profile = Profile.getLastUsedProfile();
for (Bundle bundle : likelyBundles) {
Uri uri;
try {
uri = IntentUtils.safeGetParcelable(bundle, CustomTabsService.KEY_URL);
} catch (ClassCastException e) {
continue;
}
String url = checkAndConvertUri(uri);
if (url != null) {
warmupManager.maybePreconnectUrlAndSubResources(profile, url);
atLeastOneUrl = true;
}
}
return atLeastOneUrl;
}
示例3: getCustomTabBrowsers
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
private List<String> getCustomTabBrowsers(Context context, List<ResolveInfo> browsersList) {
List<String> customTabBrowsers = new ArrayList<String>();
for (ResolveInfo info : browsersList) {
String packageName = info.activityInfo.packageName;
Intent intent = new Intent();
intent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
intent.setPackage(packageName);
if (context.getPackageManager().resolveService(intent, 0) != null) {
customTabBrowsers.add(packageName);
}
}
return customTabBrowsers;
}
示例4: toCustomTabUriBundle
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
public static List<Bundle> toCustomTabUriBundle(Uri[] uris, int startIndex) {
Preconditions.checkArgument(startIndex >= 0, "startIndex must be positive");
if (uris == null || uris.length <= startIndex) {
return Collections.emptyList();
}
List<Bundle> uriBundles = new ArrayList<>(uris.length - startIndex);
for (int i = startIndex; i < uris.length; i++) {
if (uris[i] == null) {
Logger.warn("Null URI in possibleUris list - ignoring");
continue;
}
Bundle uriBundle = new Bundle();
uriBundle.putParcelable(CustomTabsService.KEY_URL, uris[i]);
uriBundles.add(uriBundle);
}
return uriBundles;
}
示例5: postMessageFromClientApp
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
/**
* Relay a postMessage request through the current channel assigned to this session.
* @param message The message to be sent.
* @return The result of the postMessage request. Returning true means the request was accepted,
* not necessarily that the postMessage was successful.
*/
public int postMessageFromClientApp(final String message) {
if (mChannel == null || !mChannel[0].isReady() || mChannel[0].isClosed()) {
return CustomTabsService.RESULT_FAILURE_MESSAGING_ERROR;
}
if (mWebContents == null || mWebContents.isDestroyed()) {
return CustomTabsService.RESULT_FAILURE_MESSAGING_ERROR;
}
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
// It is still possible that the page has navigated while this task is in the queue.
// If that happens fail gracefully.
if (mChannel == null || mChannel[0].isClosed()) return;
mChannel[0].postMessage(message, null);
}
});
return CustomTabsService.RESULT_SUCCESS;
}
示例6: onCustomTabsConnected
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
@Override
public void onCustomTabsConnected() {
List<Bundle> otherLikelyBundles = new ArrayList<>(LIKELY_URLS.length);
for (String likelyUrl : LIKELY_URLS) {
Bundle bundle = new Bundle();
bundle.putParcelable(CustomTabsService.KEY_URL, Uri.parse(likelyUrl));
otherLikelyBundles.add(bundle);
}
if (warmUpService.mayLaunchUrl(Uri.parse(CREDITS_URL), null, otherLikelyBundles)) {
Timber.d("Successfully called mayLaunchUrl()");
} else {
Timber.d("Failed to call mayLaunchUrl()");
}
}
示例7: postMessage
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
public int postMessage(CustomTabsSessionToken session, String message, Bundle extras) {
int result;
if (!mWarmupHasBeenCalled.get()) result = CustomTabsService.RESULT_FAILURE_DISALLOWED;
if (!isCallerForegroundOrSelf() && !CustomTabActivity.isActiveSession(session)) {
result = CustomTabsService.RESULT_FAILURE_DISALLOWED;
}
// If called before a validatePostMessageOrigin, the post message origin will be invalid and
// will return a failure result here.
result = mClientManager.postMessage(session, message);
logCall("postMessage", result);
return result;
}
示例8: getPackageNameToUse
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}
示例9: testCreateSession
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
@Test
public void testCreateSession() {
startBind(true);
provideClient();
CustomTabsCallback mockCallbacks = Mockito.mock(CustomTabsCallback.class);
CustomTabsSession mockSession = Mockito.mock(CustomTabsSession.class);
Mockito.doReturn(mockSession).when(mClient).newSession(mockCallbacks);
Uri launchUri1 = Uri.parse("https://idp.example.com");
Uri launchUri2 = Uri.parse("https://another.example.com");
Uri launchUri3 = Uri.parse("https://yetanother.example.com");
Bundle launchUri2Bundle = new Bundle();
launchUri2Bundle.putParcelable(CustomTabsService.KEY_URL, launchUri2);
Bundle launchUri3Bundle = new Bundle();
launchUri3Bundle.putParcelable(CustomTabsService.KEY_URL, launchUri3);
CustomTabsSession session = mManager.createSession(
mockCallbacks,
launchUri1,
launchUri2,
launchUri3);
assertThat(session).isEqualTo(mockSession);
// upon creation of the session, the code should prime the session with the expected URIs
ArgumentCaptor<List> bundleCaptor = ArgumentCaptor.forClass(List.class);
Mockito.verify(mockSession).mayLaunchUrl(
eq(launchUri1),
eq((Bundle)null),
bundleCaptor.capture());
List<Bundle> bundles = bundleCaptor.getValue();
assertThat(bundles).hasSize(2);
assertThat(bundles.get(0).get(CustomTabsService.KEY_URL)).isEqualTo(launchUri2);
assertThat(bundles.get(1).get(CustomTabsService.KEY_URL)).isEqualTo(launchUri3);
}
示例10: testToCustomTabUri
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
@Test
public void testToCustomTabUri() {
Uri exampleUri = Uri.parse("https://www.example.com");
Uri anotherExampleUri = Uri.parse("https://another.example.com");
List<Bundle> bundles = UriUtil.toCustomTabUriBundle(
new Uri[] { exampleUri, anotherExampleUri },
0);
assertThat(bundles).hasSize(2);
assertThat(bundles.get(0).keySet()).contains(CustomTabsService.KEY_URL);
assertThat(bundles.get(0).get(CustomTabsService.KEY_URL)).isEqualTo(exampleUri);
assertThat(bundles.get(1).keySet()).contains(CustomTabsService.KEY_URL);
assertThat(bundles.get(1).get(CustomTabsService.KEY_URL)).isEqualTo(anotherExampleUri);
}
示例11: testToCustomTabUri_startIndex
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
@Test
public void testToCustomTabUri_startIndex() {
Uri anotherExampleUri = Uri.parse("https://another.example.com");
List<Bundle> bundles = UriUtil.toCustomTabUriBundle(
new Uri[] {
Uri.parse("https://www.example.com"),
anotherExampleUri
},
1);
assertThat(bundles).hasSize(1);
assertThat(bundles.get(0).keySet()).contains(CustomTabsService.KEY_URL);
assertThat(bundles.get(0).get(CustomTabsService.KEY_URL)).isEqualTo(anotherExampleUri);
}
示例12: onServiceConnected
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
@Override
public void onServiceConnected(CustomTabsClient client) {
mClient = client;
mClient.warmup(0L);
CustomTabsSession session = getSession();
session.validateRelationship(
CustomTabsService.RELATION_HANDLE_ALL_URLS, mOrigin, null);
TwaSessionCallback twaSessionCallback = mTwaSessionCallback.get();
if (twaSessionCallback != null) twaSessionCallback.onTwaSessionReady();
}
示例13: getPackagesSupportingCustomTabs
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
private List<String> getPackagesSupportingCustomTabs(PackageManager packageManager) {
List<ResolveInfo> resolvedInfoList = packageManager.queryIntentActivities(INTENT_TO_EXTERNAL_LINK, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedInfoList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (packageManager.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
return packagesSupportingCustomTabs;
}
示例14: getPackageNameToUse
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
/**
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
* the one chosen by the user if there is one, otherwise makes a best effort to return a
* valid package name.
*
* This is <strong>not</strong> threadsafe.
*
* @param context {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}
示例15: postMessage
import android.support.customtabs.CustomTabsService; //导入依赖的package包/类
public synchronized int postMessage(CustomTabsSessionToken session, String message) {
SessionParams params = mSessionParams.get(session);
if (params == null) return CustomTabsService.RESULT_FAILURE_MESSAGING_ERROR;
return params.postMessageHandler.postMessage(message);
}