我们可以在短信中传递一个 Uri 而不是 Android 中的超链接吗 [英] Can we pass a Uri in an SMS message instead of hyperlink in Android

查看:27
本文介绍了我们可以在短信中传递一个 Uri 而不是 Android 中的超链接吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们可以在 SMS 消息中传递 Uri 而不是 Android 中的超链接.我正在考虑以下情况:
1) 我打开一个 DDMS
2) 在模拟器控制面板中,我将短信发送为http://www.google.com"
3) 短信到达模拟器.
4) 我打开短信,消息 http://www.google.com 有一个超链接,如图所示.
5) 我点击该链接,它会重定向到浏览器,在其中打开 Google 网站.

I am figuring out that can we pass a Uri in an SMS message instead of hyperlink in Android. I am considering the following scenario:
1) I open a DDMS
2) In the Emulator Control panel, I am sending an SMS as "http://www.google.com"
3) The SMS arrives in the emulator.
4) I open the SMS and the message http://www.google.com has a hyperlink as shown here.
5) I click on the link and it redirects to a browser opening me the Google site in it.

考虑另一种情况:
1) 我打开一个 DDMS
2) 在模拟器控制面板中,我发送一条短信为myscheme://com.android.myhost/mypath"
3) 短信到达模拟器.
4)我打开短信,它向我显示了消息 myscheme://com.android.myhost/mypath
5) 我点击链接,它重定向到使用上述 Uri 注册的应用程序.

Consider the another scenario:
1) I open a DDMS
2) In the Emulator Control panel, I am sending an SMS as "myscheme://com.android.myhost/mypath"
3) The SMS arrives in the emulator.
4) I open the SMS and it shows me the message myscheme://com.android.myhost/mypath
5) I click on the link and it redirects to the application which is registered with the above Uri.

我该怎么做.有什么建议吗?

How do I go for this. Any suggestions?

问候和感谢
索哈伊布·拉赫曼

Regards And Thanks
Sohaib Rahman

推荐答案

我不会那样做.不要发明自己的自定义方案.

I would not do it that way. Do not invent your own custom schemes.

相反,只要您安装的应用也声称支持该特定 URL 结构,您的第一种方法就可以正常工作.

Instead, your first approach will work just fine, so long as you have an app installed that also claims to support that particular URL structure.

例如,如果您安装了 Barcode Scanner,一旦用户单击该链接,像 http://zxing.appspot.com/scan 这样的 URL 将启动 Barcode Scanner 应用程序.这是因为 Barcode Scanner 有一个带有以下 元素的活动:

For example, if you have Barcode Scanner installed, a URL like http://zxing.appspot.com/scan will launch the Barcode Scanner app once the link is clicked by the user. This is because Barcode Scanner has an activity with the following <intent-filter> element:

  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http" android:host="zxing.appspot.com" android:path="/scan"/>
  </intent-filter>

与自定义方案相比,这种方法有两个好处:

There are two benefits to this approach over custom schemes:

  1. IETF 的成员不会因为创建未经授权的计划而威胁要打断您的膝盖.:-)

  1. Members of the IETF will not threaten to break your kneecaps, for creating unauthorized schemes. :-)

该链接仍然有效,即使对于未使用 Android 或未安装 Barcode Scanner 的收件人也是如此.如果您从正在使用的 Web 浏览器访问 http://zxing.appspot.com/scan查看此 SO 答案,您将看到它指向一个有效的网页,Android 设备用户可以从中单击下载 Barcode Scanner.您的自定义方案方法创建的网址对于没有安装您的应用的任何其他人来说都是完全无用的(例如,有人试图将您的短信转发给其他人).

The link still works, even for recipients who are not on Android or do not have Barcode Scanner installed. If you visit http://zxing.appspot.com/scan from the Web browser that you are using to view this SO answer, you will see that it leads to a valid Web page, from which an Android device user could click to download Barcode Scanner. Your custom-scheme approach creates URLs that are completely useless to anyone else who does not have your app installed (e.g., somebody tries forwarding your SMS to somebody else).

现在,某种水果味的移动操作系统确实鼓励创建您自己的自定义方案,原因对我来说是深不可测的.如果您真的确定要这样做,则可以使用 <intent-filter> 和您的方案:

Now, a certain fruit-flavored mobile operating system does encourage creating your own custom schemes, for reasons that are unfathomable to me. If you are really really certain that you want to do that, you would use an <intent-filter> with your scheme in it:

  <intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="zxing" android:host="scan" android:path="/"/>
  </intent-filter>

这篇关于我们可以在短信中传递一个 Uri 而不是 Android 中的超链接吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆