Abdallah Zaky
Abdallah Zaky

Reputation: 11

How to rewrite the code to open link on Chrome custom tab

How can I rewrite the code to open link on Chrome custom tab:

imageView5 = (AppCompatImageView) findViewById(R.id.image_view5);

imageView5.setOnClickListener(
    new View.OnClickListener() {
      @Override
      public void onClick(View view3) {
        Intent intent1 =
            new Intent(Intent.ACTION_VIEW, Uri.parse("http://mekotube.com/muslim/"));
        ((HOMEActivity) getContext()).startActivity(intent1);
      }
    });

Upvotes: 1

Views: 3216

Answers (1)

andreban
andreban

Reputation: 4976

The documentation for Custom Tabs is available here.

On the Custom Tabs Github repo, There is a set of demos, showing how to use the API.

Check out the simple demo app, showing how to open it.

I'd also recommend checking out the demo on how to use the Custom Tabs Service to improve speed when opening the page.

Make sure to check out the best practices as well, as they contain valuable hints on how to handle multiple browsers among other stuff.

Here's an extract from the docs, showing how to open a simple tab, without any customisation or connecting to the Custom Tabs service.

1 - Add the Custom Tabs Support Library to your Gradle build file.

dependencies {
    ...
    implementation 'com.android.support:customtabs:28.0.0'
}

2 - Use the Support Library to open a link:

String url = "https://paul.kinlan.me/";
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));

Upvotes: 6

Related Questions