5

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.

the buttons I want to hide

Guilherme Santos
  • 328
  • 4
  • 11

2 Answers2

8

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.

2

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...

See result without download and star buttons

mikep
  • 5,880
  • 2
  • 30
  • 37
  • I would like to change the entries in the menu, especially remove the "Open with..." entry. Is there a possibility to do this? I see that among the various "extras" there is an EXTRA_UI_TYPE that I tried to modify with values from 0 to 6, but nothing happens... – Alessandro Caliaro Apr 19 '23 at 05:18
  • @AlessandroCaliaro Where you see "Open with" and what does it do? Add screen please. Anyway default menu items is not possible to hide. You can only add custom menu items but not remove default added by browser vendor. – mikep Apr 19 '23 at 08:44
  • Thanks @mikep. Instead of "Open in browser" I have "Open with chrome". The question is: can I set EXTRA_UI_TYPE? – Alessandro Caliaro Apr 19 '23 at 09:41
  • I also tried EXTRA_UI_TYPE I saw in source code that in the past was some constant e.g. "UI minimal" but it is not working now. Trust I was trying to remove as much as possible. Nowadays only sharing, star and download can be removed. – mikep Apr 19 '23 at 11:55