繁体   English   中英

检测传入SMS中是否存在http链接或URL,然后在android中以编程方式删除相同的链接

[英]Detect presence of http link or URL in incoming SMS and then delete the same programatically in android

我需要检测传入SMS中是否存在http链接或URL,然后在android中以编程方式删除相同的链接。

我需要在这个方面有所作为。 有什么帮助吗?

检测

Matthew(在SO上)写了一篇博客文章,提供了一种出色的解决方案,用于识别大多数常用格式的URL,例如:

  • www.google.com
  • http://www.google.com
  • mailto:somebody@google.com
  • somebody@google.com
  • www.url-with-querystring.com/?url=has-querystring

使用的正则表达式为:

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/

但是,我建议您访问http://blog.mattheworiordan.com/post/13174566389/url-regular-expression-for-links-with-or-without-the-来查看工作示例。

删除

停止传入消息,获取消息文本,使用上述正则表达式对其进行处理,然后使用修改后的文本模拟传入消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM