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
Related
I am using chrome custom tabs to integrate a payment gateway inside an Android App. Inside the payment gateway I have have to provide payment_success_redirect url and payment_fail_redirect for fail.
Problem here is that whether payment succeeded or failed user is redirected to the given page. Now if user presses hardware back button previous page starts loading and I do not want this.
Is there a way to prevent this or know explicitly on which URL currently I am on.
My Code:
try {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setData(Uri.parse(url));
startActivityForResult(customTabsIntent.intent, CHROME_CUSTOM_TAB_REQUEST_CODE);
} catch (Exception e) {
e.printStackTrace();
}
The API of Custom Tab component do not let the host app retrieve on which URL the user is right now, for privacy matters.
You can monitor only some navigation events as described here.
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 :)
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
I'm a web developer. I'm currently developing android application on Android Studio using WebView which access my website as an android application. One of my webpage contains many external links. My goal is to make the android application can handle external links like Gmail App does (also like facebook and Line do).
Below is the example of gmail app.
An email contains external link
Link clicked, then application open a new activity acts like a browser without leaving Gmail application
Any idea how to make it?
It is pretty simple. You have to use Chrome Custom Tabs as suggested by Gergely as well in comment. Below is the small functional code that will help you to achieve this.
First add this dependency to your build.gradle(Module:app)
compile 'com.android.support:customtabs:23.4.0'
Second add below function to your code and simply pass string URL to it.
private void redirectUsingCustomTab(String url)
{
Uri uri = Uri.parse(url);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
// set desired toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
// add start and exit animations if you want(optional)
/*intentBuilder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
android.R.anim.slide_out_right);*/
CustomTabsIntent customTabsIntent = intentBuilder.build();
customTabsIntent.launchUrl(activity, uri);
}
Rest it will take care itself. Since Chrome Custom Tabs can customised so lot can be done like you can add menu to toolbar. For detailed information you can visit official documentation from Google itself here.
Hope it will help you to start with :)
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.