public abstract class

CustomTabsServiceConnection

extends java.lang.Object

 java.lang.Object

↳androidx.browser.customtabs.CustomTabsServiceConnection

Gradle dependencies

compile group: 'androidx.browser', name: 'browser', version: '1.8.0'

  • groupId: androidx.browser
  • artifactId: browser
  • version: 1.8.0

Artifact androidx.browser:browser:1.8.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.browser:browser com.android.support:customtabs

Androidx class mapping:

androidx.browser.customtabs.CustomTabsServiceConnection android.support.customtabs.CustomTabsServiceConnection

Overview

Abstract to use while binding to a CustomTabsService. Any client implementing this is responsible for handling changes related with the lifetime of the connection like rebinding on disconnect.

Summary

Constructors
publicCustomTabsServiceConnection()

Methods
public abstract voidonCustomTabsServiceConnected(ComponentName name, CustomTabsClient client)

Called when a connection to the CustomTabsService has been established.

public final voidonServiceConnected(ComponentName name, IBinder service)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public CustomTabsServiceConnection()

Methods

public final void onServiceConnected(ComponentName name, IBinder service)

public abstract void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client)

Called when a connection to the CustomTabsService has been established.

Parameters:

name: The concrete component name of the service that has been connected.
client: CustomTabsClient that contains the IBinder with which the connection have been established. All further communication should be initiated using this client.

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.browser.customtabs;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.customtabs.ICustomTabsService;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

/**
 * Abstract {@link ServiceConnection} to use while binding to a {@link CustomTabsService}. Any
 * client implementing this is responsible for handling changes related with the lifetime of the
 * connection like rebinding on disconnect.
 */
public abstract class CustomTabsServiceConnection implements ServiceConnection {
    @Nullable
    private Context mApplicationContext;

    @RestrictTo(RestrictTo.Scope.LIBRARY)
    /* package */ void setApplicationContext(@NonNull Context context) {
        mApplicationContext = context;
    }

    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @Nullable
    /* package */ Context getApplicationContext() {
        return mApplicationContext;
    }

    @Override
    public final void onServiceConnected(@NonNull ComponentName name, @NonNull IBinder service) {
        if (mApplicationContext == null) {
            throw new IllegalStateException("Custom Tabs Service connected before an application"
                    + "context has been provided.");
        }
        onCustomTabsServiceConnected(name, new CustomTabsClient(
                ICustomTabsService.Stub.asInterface(service), name, mApplicationContext) {
        });
    }

    /**
     * Called when a connection to the {@link CustomTabsService} has been established.
     * @param name   The concrete component name of the service that has been connected.
     * @param client {@link CustomTabsClient} that contains the {@link IBinder} with which the
     *               connection have been established. All further communication should be initiated
     *               using this client.
     */
    public abstract void onCustomTabsServiceConnected(@NonNull ComponentName name,
            @NonNull CustomTabsClient client);
}