Can we pass a Uri in an SMS message instead of hyp

2019-08-14 03:54发布

问题:

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.

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

回答1:

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

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.

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. Members of the IETF will not threaten to break your kneecaps, for creating unauthorized schemes. :-)

  2. 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).

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>


标签: android sms uri