How to detect link Android device is visiting in its browser and send the url to another app?

huangapple go评论66阅读模式
英文:

How to detect link Android device is visiting in its browser and send the url to another app?

问题

I want to create an app to detect fraud/phishing links, this app acts as an overlay over browsers, how do I read the website the browser is visiting and send it to the app so that I can send the url for analysis to the backend.

如何读取浏览器正在访问的网站并将其发送到应用程序,以便我可以将URL发送到后端进行分析?

How do I read the url from the mobile browser exactly?

我如何准确地读取移动浏览器的URL?

英文:

I want to create an app to detect fraud/phishing links, this app acts as an overlay over browsers, how do I read the website the browser is visiting and send it to the app so that I can send the url for analysis to the backend.

How do I read the url from the mobile browser exactly?

答案1

得分: 1

尝试这个:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

这对我来说运行正常。

至于缺少的 "http://",我会像这样处理:

if (!url.startsWith("http://") && !url.startsWith("https://"))
   url = "http://" + url;

我还可能会在用户输入 URL 时预填充 EditText,内容为 "http://"。

英文:

Try this:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);

That works fine for me.

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
   url = "http://" + url;

I would also probably pre-populate your EditText that the user is typing a URL in with "http://".

huangapple
  • 本文由 发表于 2023年4月13日 17:20:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定