Usar a API de nível inferior da Guia personalizada

A forma recomendada de integrar seu aplicativo com guias personalizadas é usar a biblioteca de navegadores do AndroidX, mas você também pode iniciar uma guia personalizada sem a biblioteca de suporte. Este guia fornece uma visão geral de como fazer isso.

A implementação completa da Biblioteca de Suporte está disponível no GitHub e pode ser usada como ponto de partida. Ela também contém os arquivos AIDL necessários para se conectar ao serviço, já que os contidos no repositório do Chromium não podem ser usados diretamente com o Android Studio.

Noções básicas para iniciar guias personalizadas usando a API Low Level

// Using a VIEW intent for compatibility with any other browsers on device.
// Caller should not be setting FLAG_ACTIVITY_NEW_TASK or 
// FLAG_ACTIVITY_NEW_DOCUMENT. 
String url = ¨https://paul.kinlan.me/¨;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
//  Must have. Extra used to match the session. Its value is an IBinder passed
//  whilst creating a news session. See newSession() below. Even if the service is not 
//  used and there is no valid session id to be provided, this extra has to be present 
//  with a null value to launch a custom tab.

private static final String EXTRA_CUSTOM_TABS_SESSION = "android.support.customtabs.extra.SESSION";
Bundle extras = new Bundle;
extras.putBinder(EXTRA_CUSTOM_TABS_SESSION, 
   sessionICustomTabsCallback.asBinder() /* Set to null for no session */);
intent.putExtras(extras);

Como adicionar personalizações de interface

Para incluir personalizações na interface, adicione extras à intent ACTION_VIEW. Uma lista completa das teclas extras usadas para personalizar a IU pode ser encontrada nos documentos de CustomTabsIntent. Confira um exemplo de como adicionar uma cor personalizada da barra de ferramentas:

// Extra that changes the background color for the address bar. colorInt is an int
// that specifies a Color.

private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, colorInt);

Como se conectar ao serviço de guias personalizadas

O serviço de Guias Personalizadas pode ser usado da mesma forma que outros Serviços do Android. A interface é criada com AIDL e cria automaticamente uma classe de serviço de proxy para você.

Use os métodos no serviço de proxy para aquecer, criar sessões e pré-buscar:

// Package name for the Chrome channel the client wants to connect to. This
// depends on the channel name.
// Stable = com.android.chrome
// Beta = com.chrome.beta
// Dev = com.chrome.dev
public static final String CUSTOM_TAB_PACKAGE_NAME = "com.chrome.dev";  // Change when in stable

// Action to add to the service intent. This action can be used as a way 
// generically pick apps that handle custom tabs for both activity and service 
// side implementations.
public static final String ACTION_CUSTOM_TABS_CONNECTION =
       "android.support.customtabs.action.CustomTabsService";
Intent serviceIntent = new Intent(ACTION_CUSTOM_TABS_CONNECTION);

serviceIntent.setPackage(CUSTOM_TAB_PACKAGE_NAME);
context.bindService(serviceIntent, mServiceConnection,
                    Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);