I found some post in the depths of Google, there was a way to create links for text. Generally wrote, everything works, when I click on the text, I need to open 2 activations. As I understand it, you need to register something in the filter in the Manifesto, tell me what to write there.

  • 3
    What text? Where is he? Online? In TextView? Or is it a button? No one understood anything . - Yuriy SPb
  • Well, the usual TextView, Html.from here is the html code, after that it becomes a link, when you click on the link, you get a transition to the browser. Are you working with chtoli for the first time?))) This is the basis, when you click on a hyperlink, it throws it into the browser. So I need not in the browser but for 2 activations, how to do it? - ANDRO
  • Of course not the first time. Do not distort. The question is incorrectly set. There may be several options. The link may be a URL like " site.ru ", when clicked, you can open the activation. And you can specify the application in the link. The same can be done on the site. What way do you mean? - Yuriy SPb 1:56 pm
  • one
  • one
    Do this and this. Should help ... What are you looking at? does not help or what? And, you just do not see what I showed you to do? And I thought you were a telepath too, like everything here ... - Vladyslav Matviienko

1 answer 1

The question is still not completely clear due to the lack of code.

You can try this:

In the manifest:

<activity android:name=".Activity" android:label="@string/hello_world" <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="site.ru" /> <data android:scheme="http" /> <action android:name="android.intent.action.VIEW" /> </intent-filter> </activity> 

In this case, if there is a link to "http://site.ru", the TextView should open a selection dialog of what to open, in which there will be an application with activation, which is described above.

It is easier, in my opinion, to catch a click on the link and already in the handler to do anything, starting from the link:

 CharSequence sequence = Html.fromHtml(html); SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence); URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class); for (URLSpan span : urls) { makeLinkClickable(strBuilder, span); } YOURS_TEXT_VIEW.setText(strBuilder); protected void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { int start = strBuilder.getSpanStart(span); int end = strBuilder.getSpanEnd(span); int flags = strBuilder.getSpanFlags(span); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View view) { if (span.getURL().equals("http://site.ru") { context.startActivity(new Intent(context, Activity.class); } } } strBuilder.setSpan(clickable, start, end, flags); strBuilder.removeSpan(span); } 

UPD 0:

Under the link @gcoder another such option is written. The simplest:

1) In the manifest:

 <intent-filter> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.VIEW" /> <data android:scheme="com.package.name" /> </intent-filter> 

In this case, this activation will catch clicking on all links, in which instead of "http: //" will be "com.package.name://".

Accordingly, if in your TextView there is a link of the form "com.package.name: whatever is just / still-something /," then when you click it, the activation will be opened.

  • There should be no window of choice. You just need to click on the link that is in the text, and after that startActivity should occur, as it is still easier to explain. I do not understand what you want to hear from me, what you want, or still what I write? - ANDRO
  • It's easier to throw a button and set it with setOnClick and that's it. If everything were so simple, I would create a theme here ... - ANDRO
  • The second block of code must be realized in a self-proclaimed manner. Without dialogue. - Yuriy SPb
  • stackoverflow.com/questions/20791482/… Why is it so wrong? - ANDRO
  • As far as I understand, there about WebView, and you about TextView. - Yuriy SPb