Java Code Examples for android.support.customtabs.CustomTabsClient#bindCustomTabsService()

The following examples show how to use android.support.customtabs.CustomTabsClient#bindCustomTabsService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomTabs.java    From ForceDoze with GNU General Public License v3.0 6 votes vote down vote up
private Warmer warm(){
    mCustomTabServiceConnection =
            new CustomTabsServiceConnection() {
                @Override
                public void onCustomTabsServiceConnected(ComponentName componentName,
                                                         CustomTabsClient customTabsClient) {
                    mCustomTabsClient = customTabsClient;
                    mCustomTabsClient.warmup(0);
                    mCustomTabsSession = mCustomTabsClient.newSession(null);
                }

                @Override
                public void onServiceDisconnected(ComponentName name) {
                    mCustomTabsClient = null;
                }
            };

    packageNameToUse = ChromePackageHelper.getPackageNameToUse(context);

    if (packageNameToUse != null){
        CustomTabsClient.bindCustomTabsService(context, packageNameToUse,
                mCustomTabServiceConnection);
    }
    return this;
}
 
Example 2
Source File: ManageDataLauncherActivity.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String chromePackage = CustomTabsClient.getPackageName(this,
            TrustedWebUtils.SUPPORTED_CHROME_PACKAGES, false);
    if (chromePackage == null) {
        onError(new RuntimeException("No valid build of Chrome found"));
        finish();
        return;
    }

    View loadingView = createLoadingView();
    if (loadingView != null) {
        setContentView(loadingView);
    }

    CustomTabsClient.bindCustomTabsService(this, chromePackage, mServiceConnection);
}
 
Example 3
Source File: CustomTabConnectionRule.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Binds the CustomTabsService, creates a {@link CustomTabsSession} and returns it.
 */
public CustomTabsSession establishSessionBlocking(Context context) {
    mContext = context;
    if (!CustomTabsClient.bindCustomTabsService(context, context.getPackageName(),
            mConnection)) {
        fail("Failed to bind the service");
        return null;
    }
    boolean success = false;
    try {
        success = mConnectionLatch.await(2, TimeUnit.SECONDS);
    } catch (InterruptedException e) {}
    if (!success) {
        fail("Failed to connect to service");
        return null;
    }
    return mSession;
}
 
Example 4
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 ServiceConnection(this);
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
 
Example 5
Source File: CustomTabActivityHelper.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 ServiceConnection(this);
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
 
Example 6
Source File: HassActivity.java    From home-assistant-Android with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (menu instanceof MenuBuilder) {
        ((MenuBuilder) menu).setOptionalIconsVisible(true);
    }
    String packageName = CustomTabsClient.getPackageName(this, null);
    CustomTabsClient.bindCustomTabsService(this, !TextUtils.isEmpty(packageName) ? packageName : "com.android.chrome", chromeConnection);
    getMenuInflater().inflate(R.menu.hass, menu);
    return super.onCreateOptionsMenu(menu);
}
 
Example 7
Source File: SettingsActivity.java    From home-assistant-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    //noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    String packageName = CustomTabsClient.getPackageName(this, null);
    CustomTabsClient.bindCustomTabsService(this, !TextUtils.isEmpty(packageName) ? packageName : "com.android.chrome", chromeConnection);
}
 
Example 8
Source File: CustomTabActivityHelper.java    From AndroidProjects with MIT License 5 votes vote down vote up
/**
     * 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 ServiceConnection(this);
        mConnection = new org.chromium.customtabsclient.shared.ServiceConnection(this);
        CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
    }
 
Example 9
Source File: CustomTabsController.java    From Auth0.Android with MIT License 5 votes vote down vote up
/**
 * Attempts to bind the Custom Tabs Service to the Context.
 */
public void bindService() {
    Log.v(TAG, "Trying to bind the service");
    Context context = this.context.get();
    isBound = false;
    if (context != null && preferredPackage != null) {
        isBound = CustomTabsClient.bindCustomTabsService(context, preferredPackage, this);
    }
    Log.v(TAG, "Bind request result: " + isBound);
}
 
Example 10
Source File: CustomTabActivityHelper.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * 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 ServiceConnection(this);
    CustomTabsClient.bindCustomTabsService(activity, packageName, mConnection);
}
 
Example 11
Source File: TwaLauncher.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private void launchTwa(TrustedWebActivityIntentBuilder twaBuilder,
        @Nullable SplashScreenStrategy splashScreenStrategy,
        @Nullable Runnable completionCallback) {
    if (splashScreenStrategy != null) {
        splashScreenStrategy.onTwaLaunchInitiated(mProviderPackage, twaBuilder);
    }

    Runnable onSessionCreatedRunnable = () ->
            launchWhenSessionEstablished(twaBuilder, splashScreenStrategy, completionCallback);

    if (mSession != null) {
        onSessionCreatedRunnable.run();
        return;
    }

    Runnable onSessionCreationFailedRunnable = () -> {
        // The provider has been unable to create a session for us, we can't launch a
        // Trusted Web Activity. We could either exit, forcing the user to try again,
        // hopefully successfully this time or we could launch a Custom Tab giving the user
        // a subpar experience (compared to a TWA).
        // We'll open in a CCT, but pay attention to what users want.
        launchCct(twaBuilder, completionCallback);
    };

    if (mServiceConnection == null) {
        mServiceConnection = new TwaCustomTabsServiceConnection();
    }

    mServiceConnection.setSessionCreationRunnables(
            onSessionCreatedRunnable, onSessionCreationFailedRunnable);
    CustomTabsClient.bindCustomTabsService(mContext, mProviderPackage, mServiceConnection);
}
 
Example 12
Source File: MainActivity.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private void bindCustomTabsService() {
    if (mClient != null) return;
    if (TextUtils.isEmpty(mPackageNameToBind)) {
        mPackageNameToBind = CustomTabsHelper.getPackageNameToUse(this);
        if (mPackageNameToBind == null) return;
    }
    mConnection = new ServiceConnection(this);
    boolean ok = CustomTabsClient.bindCustomTabsService(this, mPackageNameToBind, mConnection);
    if (ok) {
        mConnectButton.setEnabled(false);
    } else {
        mConnection = null;
    }
}
 
Example 13
Source File: CustomTabsHelper.java    From rides-android-sdk with MIT License 5 votes vote down vote up
/**
 * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
 *
 * @param context The host context.
 * @param customTabsIntent a CustomTabsIntent to be used if Custom Tabs is available.
 * @param uri the Uri to be opened.
 * @param fallback a CustomTabFallback to be used if Custom Tabs is not available.
 */
public void openCustomTab(
        final Context context,
        final CustomTabsIntent customTabsIntent,
        final Uri uri,
        CustomTabFallback fallback) {
    final String packageName = getPackageNameToUse(context);

    if (packageName != null) {
        connection = new CustomTabsServiceConnection() {
            @Override
            public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) {
                client.warmup(0L); // This prevents backgrounding after redirection

                customTabsIntent.intent.setPackage(packageName);
                customTabsIntent.intent.setData(uri);
                customTabsIntent.launchUrl(context, uri);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        };
        CustomTabsClient.bindCustomTabsService(context, packageName, connection);
    } else if (fallback != null) {
        fallback.openUri(context, uri);
    } else {
        Log.e(UberSdk.UBER_SDK_LOG_TAG, "Use of openCustomTab without Customtab support or a fallback set");
    }
}
 
Example 14
Source File: CustomTabServiceHelper.java    From cordova-plugin-safariviewcontroller with MIT License 5 votes vote down vote up
/**
 * Binds the Activity to the Custom Tabs Service.
 * @param activity the activity to be binded to the service.
 */
public boolean bindCustomTabsService(Activity activity) {
    if (mClient != null) return false;

    if (mPackageNameToBind == null) return false;

    mConnection = new ServiceConnection(this);
    CustomTabsClient.bindCustomTabsService(activity, mPackageNameToBind, mConnection);
    return true;
}
 
Example 15
Source File: Browser.java    From OsmGo with MIT License 4 votes vote down vote up
protected void handleOnResume() {
  boolean ok = CustomTabsClient.bindCustomTabsService(getContext(), CUSTOM_TAB_PACKAGE_NAME, connection);
  if (!ok) {
    Log.e(getLogTag(), "Error binding to custom tabs service");
  }
}
 
Example 16
Source File: ChromeCustomTabsManager.java    From Anecdote with Apache License 2.0 4 votes vote down vote up
/**
 * Bins to custom chrome tab service
 */
public void bindCustomTabsService(Context context) {
    if (mClient != null) return;
    mConnection = new ChromeCustomTabsConnection(this);
    CustomTabsClient.bindCustomTabsService(context, CHROME_PACKAGE, mConnection);
}