Reputation: 358
I'm using a Chrome Custom Tab on my app and I'd like to be able to disable a few buttons that pop up automatically when I launch it to open a Google drive file, namely the button for bookmarking the page and the button for downloading it. I've searched throughout the web with no luck whatsoever.
Below is the image highlighting which buttons exactly I seek to hide in my custom tab. Anyone knows how to achieve this?! Thank you so much in advance.
Upvotes: 6
Views: 4249
Reputation: 7448
Latest years for custom tabs we should use package androidx.browser
https://developer.android.com/jetpack/androidx/releases/browser
dependencies {
...
implementation "androidx.browser:browser:1.5.0"
...
}
To use extra features...
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
// official way to disable share button
builder.setShareState(CustomTabsIntent.SHARE_STATE_OFF);
// official way to show website title in address bar
builder.setShowTitle(true);
CustomTabsIntent customTabsIntent = builder.build();
// unofficial way to show website title in address bar
customTabsIntent.intent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE, 1);
// unofficial (only) way to disable download button
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON", true);
// unofficial (only) way to disable star button
customTabsIntent.intent.putExtra("org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_STAR_BUTTON", true);
customTabsIntent.launchUrl(mainActivity, Uri.parse("https://example.com"));
What you can change you can see here https://chromium.googlesource.com/external/github.com/GoogleChrome/custom-tabs-client/+/master/customtabs/src/android/support/customtabs/CustomTabsIntent.java but almost all of constants there you can change officialy by doc here:
More interesting is what you can also change is in Chromium source code here: https://chromium.googlesource.com/chromium/src/+/refs/tags/103.0.5052.1/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabIntentDataProvider.java ... and just here is EXTRA_DISABLE_DOWNLOAD_BUTTON & EXTRA_DISABLE_STAR_BUTTON
See result without download and star buttons...
Upvotes: 5
Reputation: 151
There is a "hidden" API that lets you hide these buttons: add an extra with the key org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_STAR_BUTTON
and the value true
to the Intent before launching it to disable the bookmark button, and one with the key org.chromium.chrome.browser.customtabs.EXTRA_DISABLE_DOWNLOAD_BUTTON
to disable the download button.
Note that this doesn't fully disable the functionality: It's still possible to reparent the custom tab to Chrome and add a bookmark or download the page there.
Also note that this is not a public API, so it might disappear in future versions of Chrome.
Upvotes: 8