Linkify调用java代码

发布于 2024-09-09 06:26:18 字数 114 浏览 1 评论 0原文

有没有办法让 Linkify 链接调用我的 Activity 中的方法,或者我只允许使用 Linkify 创建链接其他活动/应用程序等?

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.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天荒地未老 2024-09-16 06:26:19

您也可以放弃使用 linkify,而只使用 linkify 的正则表达式将可点击的跨度附加到您想要的位置。这些可点击的跨度可以调用您的代码。

下面是一个示例:Android:从可点击文本启动活动

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

只等公子 2024-09-16 06:26:19

听起来你已经解决了其中的几个问题。缺少的部分似乎是在前台有一个现有的 Activity 接收 Intent。您可以通过在清单中将 Activity 声明为 singleTop 来实现此目的 (android:launchMode="singleTop")。

因此工作流程如下所示:

1) 通过 addLinks 与正则表达式、Linkify.Matcher 和 Linkify.TransformFilter 链接文本

2) 设置接收器以捕获由​​单击的链接启动的 Intent。

3)在关联的BroadcastReceiver的onReceive中,设置一个Intent来封装您的链接已被点击的事实。然后在 Activity(已经在前台)上调用 startActivity,传递 Intent。

4) 在 Activity 的 onResume 回调中,检查 Intent 以查看是否应该调用该函数。

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.

夏日落 2024-09-16 06:26:19

您可以设置一个接收器来侦听特定方案,当您单击链接时,会调用以该方案开头的某个 url。

检查此答案以了解更多详细信息。

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.

末骤雨初歇 2024-09-16 06:26:19

没有。 Linkify 附带:

  • EMAIL_ADDRESSES
  • MAP_ADDRESSES
  • PHONE_NUMBERS
  • WEB_URLS

您可以尝试扩展它。 这是 src 代码。

Nope. Linkify comes with:

  • EMAIL_ADDRESSES
  • MAP_ADDRESSES
  • PHONE_NUMBERS
  • WEB_URLS

You can try extending it. Here's the src code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文