android - Linkify links in textview and let user select which program open links instead of internal browser -



android - Linkify links in textview and let user select which program open links instead of internal browser -

i have textview applied linkify create links.

linkify.addlinks(mtextview, linkify.all);

now when users click on links, apps open links in native browser. want users have alternative select favorite browser showing "complete action using" dialog.

how can add together feature linkified links?

you can utilize clickablespan, , set textview it

public class linkspan extends clickablespan {

private onclicklistener listener; public linkspan(onclicklistener listener){ this.listener = listener; } @override public void onclick(view widget) { listener.onclick(widget); } } public class linkifyutil { private activity activity; public linkifyutil(activity activity){ this.activity = activity; } public void addautochooserlink(final intent intent,textview text){ string source = text.gettext().tostring(); string pattern = "android"; pattern p = pattern.compile(pattern); matcher m = p.matcher(source); spannablestring s = new spannablestring(source); while(m.find()){ s.setspan(new linkspan(new onclicklistener(){ @override public void onclick(view v) { //you can define intent intent.setaction(intent.action_view); intent.setdata(uri.parse("http://developer.android.com")); intent.createchooser(intent, "choose app"); activity.startactivity(intent); } }), m.start(), m.start()+pattern.length(), spanned.span_inclusive_exclusive); } text.settext(s); text.setmovementmethod(linkmovementmethod.getinstance()); } }

you can utilize linkifyutil this:

intent intent = new intent(); linkifyutil linkify = new linkifyutil(this); linkify.addautochooserlink(intent, text);

android linkify

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -