use of androidx.browser.customtabs.CustomTabsClient in project SpaceLaunchNow-Android by ItsCalebJones.
the class CustomTabActivityHelper method bindCustomTabsService.
/**
* Binds the Activity to the Custom Tabs Service
*
* @param activity the activity to be binded to the service
*/
public void bindCustomTabsService(Activity activity) {
Timber.v("Binding CustomTabService");
if (mClient != null)
return;
String packageName = CustomTabHelper.getPackageNameToUse(activity);
if (packageName == null)
return;
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0L);
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsConnected();
// Initialize a session as soon as possible.
Timber.v("Initializing CustomTabsService");
getSession();
}
@Override
public void onServiceDisconnected(ComponentName name) {
Timber.v("Disconnecting CustomTabsService");
mClient = null;
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsDisconnected();
}
};
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
use of androidx.browser.customtabs.CustomTabsClient in project SpaceLaunchNow-Android by ItsCalebJones.
the class CustomTabActivityHelper method bindCustomTabsService.
/**
* Binds the Activity to the Custom Tabs Service
*
* @param activity the activity to be binded to the service
*/
public void bindCustomTabsService(Activity activity) {
Timber.v("Binding CustomTabService");
if (mClient != null)
return;
String packageName = CustomTabHelper.getPackageNameToUse(activity);
if (packageName == null)
return;
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0L);
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsConnected();
// Initialize a session as soon as possible.
Timber.v("Initializing CustomTabsService");
getSession();
}
@Override
public void onServiceDisconnected(ComponentName name) {
Timber.v("Disconnecting CustomTabsService");
mClient = null;
if (mConnectionCallback != null)
mConnectionCallback.onCustomTabsDisconnected();
}
};
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
use of androidx.browser.customtabs.CustomTabsClient in project router-companion-android by rm3l.
the class CustomTabActivityHelper method bindCustomTabsService.
/**
* Binds the Activity to the Custom Tabs Service
*
* @param activity the activity to be binded to the service
*/
public void bindCustomTabsService(Activity activity) {
if (mClient != null) {
return;
}
String packageName = CustomTabsHelper.getPackageNameToUse(activity);
if (packageName == null) {
return;
}
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {
mClient = client;
mClient.warmup(0L);
if (mConnectionCallback != null) {
mConnectionCallback.onCustomTabsConnected();
}
// Initialize a session as soon as possible.
getSession();
}
@Override
public void onServiceDisconnected(ComponentName name) {
mClient = null;
if (mConnectionCallback != null) {
mConnectionCallback.onCustomTabsDisconnected();
}
}
};
CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
use of androidx.browser.customtabs.CustomTabsClient in project android-browser-helper by GoogleChrome.
the class MainActivity method onStart.
@Override
protected void onStart() {
super.onStart();
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(@NonNull ComponentName name, @NonNull CustomTabsClient client) {
mSession = client.newSession(null);
client.warmup(0);
mExtraButton.setEnabled(true);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
};
String packageName = CustomTabsClient.getPackageName(MainActivity.this, null);
if (packageName == null) {
Toast.makeText(this, "Can't find a Custom Tabs provider.", Toast.LENGTH_SHORT).show();
return;
}
CustomTabsClient.bindCustomTabsService(this, packageName, mConnection);
}
use of androidx.browser.customtabs.CustomTabsClient in project Anki-Android by ankidroid.
the class CustomTabActivityHelperTest method invalidClientMeansFallbackIsCalled.
@Test
public void invalidClientMeansFallbackIsCalled() {
CustomTabsClient badClient = getClientThrowingSecurityException();
CustomTabActivityHelper customTabActivityHelper = getValidTabHandler();
customTabActivityHelper.onServiceConnected(badClient);
CustomTabActivityHelper.CustomTabFallback fallback = mock(CustomTabActivityHelper.CustomTabFallback.class);
Activity activity = mock(Activity.class);
PackageManager packageManager = mock(PackageManager.class);
when(activity.getPackageManager()).thenReturn(packageManager);
when(packageManager.queryIntentActivities(any(), anyInt())).thenReturn(Collections.emptyList());
CustomTabActivityHelper.openCustomTab(activity, null, null, fallback);
verify(fallback, times(1)).openUri(any(), any());
}
Aggregations