0

So i have a textView and sometimes my textView contains links, currently when i click in this link an intent with a list of downloaded browsers opens. now what i want is, i wanna open this link inside the current app, say in a WebView. how can i do this?

we do have multiple articles/questions on same topic but i have no idea what this articles/questions are really about.

like this one https://gist.github.com/ksoichiro/3394338 gave me an ClassCastException android.text.style.URLSpan cannot be cast to pb.myPackage.LinkUtils$SensibleUrlSpan

or this one handle textview link click in my android app

is there's any straight simple way to achieve this? please let me know.

Community
  • 1
  • 1
remy boys
  • 2,928
  • 5
  • 36
  • 65
  • 1
    refer this answer [Open URL in WebView instead of default Browser](http://stackoverflow.com/questions/22962621/open-url-in-webview-instead-of-default-browser) – sajan Feb 11 '17 at 14:38

1 Answers1

0

You could use Chrome Custom Tabs, this is faster than a webview in loading webpages and is pretty simple to customize.

First include the Library:

dependencies {
    ...
    compile 'com.android.support:customtabs:25.1.1'
}

Then in your Activity when you call the method to open a browser add these lines of java:

String url = ¨https://google.com/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent intent = builder.build();
intent.launchUrl(this, Uri.parse(url));

Refer to it's docs for more customization at:
https://developer.chrome.com/multidevice/android/customtabs

Adi
  • 5,560
  • 1
  • 24
  • 37