CustomTabsSession.java revision e0c6f48d5720470e799122532699fc89d5165307
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.support.customtabs; 18 19import android.content.ComponentName; 20import android.net.Uri; 21import android.os.Build; 22import android.os.Bundle; 23import android.os.IBinder; 24import android.os.RemoteException; 25 26import java.lang.reflect.Method; 27import java.util.List; 28 29/** 30 * A class to be used for Custom Tabs related communication. Clients that want to launch Custom Tabs 31 * can use this class exclusively to handle all related communication. 32 */ 33public final class CustomTabsSession { 34 private static final String TAG = "CustomTabsSession"; 35 private final ICustomTabsService mService; 36 private final ICustomTabsCallback mCallback; 37 private final ComponentName mComponentName; 38 39 /* package */ CustomTabsSession( 40 ICustomTabsService service, ICustomTabsCallback callback, ComponentName componentName) { 41 mService = service; 42 mCallback = callback; 43 mComponentName = componentName; 44 } 45 46 /** 47 * Tells the browser of a likely future navigation to a URL. 48 * The most likely URL has to be specified first. Optionally, a list of 49 * other likely URLs can be provided. They are treated as less likely than 50 * the first one, and have to be sorted in decreasing priority order. These 51 * additional URLs may be ignored. 52 * All previous calls to this method will be deprioritized. 53 * 54 * @param url Most likely URL. 55 * @param extras Reserved for future use. 56 * @param otherLikelyBundles Other likely destinations, sorted in decreasing 57 * likelihood order. Inside each Bundle, the client should provide a 58 * {@link Uri} using {@link CustomTabsService#KEY_URL} with 59 * {@link Bundle#putParcelable(String, android.os.Parcelable)}. 60 * @return true for success. 61 */ 62 public boolean mayLaunchUrl(Uri url, Bundle extras, List<Bundle> otherLikelyBundles) { 63 try { 64 return mService.mayLaunchUrl(mCallback, url, extras, otherLikelyBundles); 65 } catch (RemoteException e) { 66 return false; 67 } 68 } 69 70 /* package */ IBinder getBinder() { 71 return mCallback.asBinder(); 72 } 73 74 /* package */ ComponentName getComponentName() { 75 return mComponentName; 76 } 77}