CustomTabsClient
public
class
CustomTabsClient
extends Object
java.lang.Object
|
↳ |
androidx.browser.customtabs.CustomTabsClient
|
Class to communicate with a CustomTabsService
and create
CustomTabsSession
from it.
Summary
Public methods |
static
boolean
|
bindCustomTabsService(Context context, String packageName, CustomTabsServiceConnection connection)
Bind to a CustomTabsService using the given package name and
ServiceConnection .
|
static
boolean
|
bindCustomTabsServicePreservePriority(Context context, String packageName, CustomTabsServiceConnection connection)
Bind to a CustomTabsService using the given package name and
ServiceConnection .
|
static
boolean
|
connectAndInitialize(Context context, String packageName)
Connects to the Custom Tabs warmup service, and initializes the browser.
|
Bundle
|
extraCommand(String commandName, Bundle args)
Can be used as a channel between the Custom Tabs client and the provider to do something that
is not part of the API yet.
|
static
String
|
getPackageName(Context context, List<String> packages)
Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler.
|
static
String
|
getPackageName(Context context, List<String> packages, boolean ignoreDefault)
Returns the preferred package to use for Custom Tabs.
|
CustomTabsSession
|
newSession(CustomTabsCallback callback)
Creates a new session through an ICustomTabsService with the optional callback.
|
CustomTabsSession
|
newSession(CustomTabsCallback callback, int id)
Creates a new session or updates a callback for the existing session
through an ICustomTabsService.
|
boolean
|
warmup(long flags)
Warm up the browser process.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public methods
connectAndInitialize
public static boolean connectAndInitialize (Context context,
String packageName)
Connects to the Custom Tabs warmup service, and initializes the browser.
This convenience method connects to the service, and immediately warms up the Custom Tabs
implementation. Since service connection is asynchronous, the return code is not the return
code of warmup.
This call is optional, and clients are encouraged to connect to the service, call
warmup()
and create a session. In this case, calling this method is not
necessary.
Parameters |
context |
Context : Context to use to connect to the remote service. |
packageName |
String : Package name of the target implementation. |
Returns |
boolean |
Whether the binding was successful.
|
extraCommand
public Bundle extraCommand (String commandName,
Bundle args)
Can be used as a channel between the Custom Tabs client and the provider to do something that
is not part of the API yet.
Parameters |
commandName |
String |
args |
Bundle |
getPackageName
public static String getPackageName (Context context,
List<String> packages)
Returns the preferred package to use for Custom Tabs, preferring the default VIEW handler.
Parameters |
context |
Context |
packages |
List |
getPackageName
public static String getPackageName (Context context,
List<String> packages,
boolean ignoreDefault)
Returns the preferred package to use for Custom Tabs.
The preferred package name is the default VIEW intent handler as long as it supports Custom
Tabs. To modify this preferred behavior, set ignoreDefault
to true and give a
non empty list of package names in packages
.
This method queries the PackageManager
to determine which packages support the
Custom Tabs API. On apps that target Android 11 and above, this requires adding the
following package visibility elements to your manifest.
<!-- Place inside the <queries> element. -->
<intent>
<action android:name="android.support.customtabs.action.CustomTabsService" />
</intent>
Parameters |
context |
Context : Context to use for querying the packages. |
packages |
List : Ordered list of packages to test for Custom Tabs support, in
decreasing order of priority. |
ignoreDefault |
boolean : If set, the default VIEW handler won't get priority over other browsers. |
Returns |
String |
The preferred package name for handling Custom Tabs, or null .
|
newSession
public CustomTabsSession newSession (CustomTabsCallback callback)
Creates a new session through an ICustomTabsService with the optional callback. This session
can be used to associate any related communication through the service with an intent and
then later with a Custom Tab. The client can then send later service calls or intents to
through same session-intent-Custom Tab association.
Parameters |
callback |
CustomTabsCallback : The callback through which the client will receive updates about the created
session. Can be null. All the callbacks will be received on the UI thread. |
Returns |
CustomTabsSession |
The session object that was created as a result of the transaction. The client can
use this to relay session specific calls.
Null if the service failed to respond (threw a RemoteException).
|
newSession
public CustomTabsSession newSession (CustomTabsCallback callback,
int id)
Creates a new session or updates a callback for the existing session
through an ICustomTabsService. This session can be used to associate any related
communication through the service with an intent and then later with a Custom Tab.
The client can then send later service calls or intents to through same
session-intent-Custom Tab association.
Parameters |
callback |
CustomTabsCallback : The callback through which the client will receive updates about the created
session. Can be null. All the callbacks will be received on the UI thread. |
id |
int : The session id. If the session with the specified id already exists for the given
client application, the new callback is supplied to that session and further
attempts to launch URLs using that session will update the existing Custom Tab
instead of launching a new one. |
Returns |
CustomTabsSession |
The session object that was created as a result of the transaction. The client can
use this to relay session specific calls.
Null if the service failed to respond (threw a RemoteException).
If null is returned, attempt using newSession(CustomTabsCallback)
which is supported with older browsers.
|
warmup
public boolean warmup (long flags)
Warm up the browser process.
Allows the browser application to pre-initialize itself in the background. Significantly
speeds up URL opening in the browser. This is asynchronous and can be called several times.
Parameters |
flags |
long : Reserved for future use. |
Returns |
boolean |
Whether the warmup was successful.
|