Reputation: 6606
I am attempting to make a custom linkfy class that will catch twitter #hashtags @mentions and URLs in a text string and have it launch another activity so far I have been able to find some code but the two problems are that it catches URLs and @mentions but not #hashtags and instead of being caught by another activity I set up with an intent filter it instead just launches the browser, below I have attached my code, any help will go a long way
This is my main Activity
TextView textView = (TextView) findViewById(R.id.tweet);
String str = "@aman_vivek how are u #aman_vivek <http://www.google.com> <http://www.tekritisoftware.com>";
textView.setText(str);
Pattern wikiWordMatcher = Pattern.compile("(@[a-zA-Z0-9_]+)");
String wikiViewURL = "http://www.twitter.com/";
Linkify.addLinks(textView, wikiWordMatcher, wikiViewURL);
Pattern wikiWordMatcher1 = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
Linkify.addLinks(textView, wikiWordMatcher1, null);
And this is my Intent filter for my class that should catch the Intent
<activity
android:name=".DirectMessageActivity"
android:label="@string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http://www.twitter.com/" />
</intent-filter>
</activity>
Upvotes: 0
Views: 1619
Reputation: 744
Although it's too late, but it might help someone else, here is an article on how you can catch hashtags in your android app and then call another activity.
Upvotes: 1
Reputation: 1006594
it catches URLs and @mentions but not #hashtags
That would be because you have not done anything in your code to catch hashtags.
and instead of being caught by another activity I set up with an intent filter it instead just launches the browser
That would be because http://www.twitter.com/
is not a scheme, and your <data>
element claims that it is. Try using http
for the scheme and www.twitter.com
for the host. Note that this will mean any attempt by users on your device to visit Twitter URLs will bring up your app as an option, which may cause them to come after you with shotguns. You may be better served converting them to some other domain, that you own, to limit possible collision.
Upvotes: 0