Custom Tabs keeps opening web browser - android

I am trying to load a web url by using Custom Tabs.
I am using following version of custom tabs
implementation 'com.android.support:customtabs:27.1.1'
The issue is that it keeps opening chrome web browser instead of custom tabs type layout descibed in the below picture.
This is my code.
public void createCustomTab(String url){
// CustomTabsIntent.Builder used to configure CustomTabsIntent.
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
// CustomTabsIntent used to launch the URL
CustomTabsIntent customTabsIntent = builder.build();
// Open the Custom Tab
customTabsIntent.launchUrl(eContext, Uri.parse(url));
}
I am trying this on a Lollipop device, and my current target SDK is 27

Related

How to force Custom Tabs to launch as Desktop site everytime?

I'm trying to implement custom tabs into my app
https://developer.chrome.com/docs/android/custom-tabs/integration-guide/
I've successfully launched the website using
#OnClick(R.id.btn_launch)
void onLaunchBtnClick(){
String url = "https://paul.kinlan.me/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
}
However it's launching as a mobile site everytime.
How can I force it to launch as a desktop site without having the user clicking checkbox?

How to load chrome custom tab when multiple browsers installed in the device and user has set different browser as default instead of chrome browser?

I am developing one android application in that i need to load all the web URL into chrome custom tab but i am facing one issue when user install multiple browser into their device and they set default browser as different instead of chrome browser in this case chrome tab is not getting open.
I am following this document and sample.
https://developer.chrome.com/multidevice/android/customtabs
https://github.com/GoogleChrome/custom-tabs-client
You can add the Google Chrome package to the customTabsIntent:
CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder().build();
tabsIntent.intent.setPackage("com.android.chrome");
tabsIntent.launchUrl(context, Uri.parse(YOUR_URL));
Try this
public static void CustomTab(Activity activity,
Uri uri) {
// It returns the chrome package name
String packageName = CustomTabsHelper.getPackageNameToUse(activity, mUrl);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
mCustomTabsIntent = builder
.setShowTitle(true)
.build();
builder.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary));
if ( packageName != null ) {
mCustomTabsIntent.intent.setPackage(packageName);
}
mCustomTabsIntent.launchUrl(activity, uri);
}
If user has installed chrome it will open directly

Chrome Custom Tabs customisations like setToolbarColor, start and exit animations are not working

I am new to Android and trying to open link in Chrome Custom Tabs. I have created a funtion to open any links on the app in Chrome Custom Tabs:
public static void chromeCustomTab(Context context, String url)
{
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(context,Uri.parse(url));
builder.setToolbarColor(context.getResources().getColor(R.color.colorPrimaryDark));
builder.setStartAnimations(context, R.anim.slide_in_bottom, R.anim.slide_out_top);
builder.setExitAnimations(context, R.anim.slide_in_top, R.anim.slide_out_bottom);
}
Now the links are opening in Chrome Custom Tabs, but none of the cosutomizations are working. The ToolbarColor is not changing, the animations are not working.
Also, the site title is not visible on the Chrome Custome Tab, only the base url is visible.
Please help me where I am going wrong on this.
add the builder settings BEFORE you launch the url :)

Disable swipe to refresh in chrome CustomTab

I'm using chrome CustomTab to open a url inside my app, using customTabsIntent.launchUrl method and CustomTabsIntent.Builder. Here's how I'm doing it right now:
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(someUrl);
is there any way to disable the swipetorefresh behaviour that is set by default, in the CustomTab? by modifying the builder or something? (without making any changes to the website)
No, This is not currently possible, as Custom Tabs will respect the behaviour of the opened web page. If changing the page is possible, these instructions can help

How to add EXTRA_REFERRER to CustomTabsIntent builder in Chrome custom tab for Android

I am using newly launched Chrome Custom tabs for android instead of using webviews. This is the link to their documentation
Here is the code that shows how to use it.
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
Question is that I want to add Intent.EXTRA_REFERRER to this. below is the para copied from their blog in their own words..
It's usually very important for websites to track where their traffic
is coming from. Make sure you let them know you are sending them users
by setting the referrer when launching your Custom Tab
intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName()));
I failed to figure out any intent created to launch custom tabs.. Where to add this line?? If somebody has came across this, help please.
you can put the extra on the Intent that is inside the CustomTabsIntent created by the builder like the following:
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse("android-app://" + context.getPackageName()));
customTabsIntent.launchUrl(this, Uri.parse(url));
Explanation: Under the hood, a Custom tab is opened by using regular a Intent with a set of Extras that configure the UI customization. It's possible to see more on how it works at the Low Level API section of the docs. When CustomTabsIntent.Builder#build() is called, it creates a CustomTabsIntent, with a properly configured Intent inside it. This intent is still exposed by the API and that's what we use to add the EXTRA_REFERRER.

Categories

Resources