Linkify to call java code
Is there a way to have a Linkify
'd link call a method in my Activity
or am I only allowed to use Linkify
to开发者_运维问答 create links to other activities / apps etc.?
YOu could also just abandon using linkify and just use the regex of linkify to go and attach clickable spans to the places you want. Those clickable spans can call into your code.
Here's an example: Android: Launch activity from clickable text
It sounds like you've got several pieces of this worked out. The missing piece seems to be having an existing Activity which is in the foreground receive the Intent. You can do that by declaring the Activity to be singleTop in the Manifest (android:launchMode="singleTop"
).
So the workflow looks like:
1) Linkify the text by addLinks with your regex, Linkify.Matcher, and Linkify.TransformFilter
2) Set up a receiver to catch the Intent launched by the clicked link.
3) In the onReceive of the associated BroadcastReceiver, set up an Intent to encapsulate the fact that your link has been clicked. Then call startActivity on the Activity (which is already in the foreground), passing the Intent.
4) In the onResume callback on the Activity, check the Intent to see if the function should be called.
You can set a receiver which will listen for a particular scheme and when you click on the link call some url starting with that scheme.
Check this answer for more details.
Nope. Linkify comes with:
EMAIL_ADDRESSES
MAP_ADDRESSES
PHONE_NUMBERS
WEB_URLS
You can try extending it. Here's the src code.
精彩评论