浏览器自定义协议,目前感觉UC浏览器做的是最棒的了。支持的比较全,当然,国外的chrome也支持的比较好。但是它似乎对这个并不感兴趣。
针对短信协议:SMS URI SCHEME,要支持四种协议:sms: sms:// smsto: smsto://
针对电话只有这一种:tel:
针对邮箱格式也只有这一种,只不过后面可以带参数:mailto:
针对intent:协议,目前4.2的android源码中就支持这种协议,相关的 协议方法参看:Intent中parseUri, toUri。
具体的格式要求可以参考维基百科中的文档:http://en.wikipedia.org/wiki/URI_scheme
Iphone支持的自定义协议
http://wiki.akosma.com/IPhone_URL_Schemes#SMS
第一:sms uri scheme
浏览器自定义协议测试 sms: smsto: sms:// smsto:// mms: mmsto: mms:// mmsto://
短信发送模式包括:
1.使用SMSManager发送短信,发送的短信不存于“信息”中。
2.使用ContentResolver发送短信,短信存放于“信息”中。
3.使用Intent发送短信,调用系统的“信息”程序发送
1.使用SMSManager发送短信,发送的短信不存于“信息”中。
2.使用ContentResolver发送短信,短信存放于“信息”中。
3.使用Intent发送短信,调用系统的“信息”程序发送
MMS
The Multimedia Messaging Service (MMS) is the standard way to send messages with multimedia content (images, video, or any attached content).
all international numbers MUST begin with a "+" character.
1. Both must be either a <local-number> or a <global-number<, i.e., start with a "+". 2. The <global-number-digits> and the <local-number-digits> must be equal, after removing all visual separators.
参考链接:
http://www.ericfeminella.com/blog/2013/01/01/invoking-native-mobile-applications-with-uri-schemes/
http://www.ericfeminella.com/blog/2013/01/01/invoking-native-mobile-applications-with-uri-schemes/
http://tools.ietf.org/html/draft-wilde-sms-uri-20
http://www.ietf.org/rfc/rfc5724.txt
http://www.linuxidc.com/Linux/2013-07/86972.htm
http://blog.youkuaiyun.com/sam_zhang1984/article/details/7095885
http://www.nfc-research.at/fileadmin/papers/2011/smsuribug_mr.pdf
http://developer.51cto.com/art/201001/181339.htm
http://www.linuxidc.com/Linux/2010-08/27943.htm
我自己写的一些测试例子:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<pre>
<a href="sms:10010">联通客服</a>
sms:
<a href="sms:">Send an SMS</a> sms: <br/>
sms://
<a href="sms://">Send an SMS</a> sms:// <br/>
sms://?body=Visit%20the%20best%20site%20at%20http://mobilexweb.com
<a href="sms://?body=Visit%20the%20best%20site%20at%20http://mobilexweb.com"> sms://?body=Visit <a><br/>
sms://+3490322111
<a href="sms://+3490322111"> sms://+3490322111 </a>
sms://+3490322111?body=Interested%20in%20Product%20AA2
<a href="sms://+3490322111?body=Interested%20in%20Product%20AA2"> sms://+3490322111?body=Interested%20in%20Product%20AA2 </a><br/>
sms:+15105550101?body=hello%20there
<a href="sms:+15105550101?body=hello%20there"> sms:+15105550101?body=hello%20there </a> <br/>
sms:+15105550101,+15105550102?body=hello%20there
<a href="sms:+15105550101,+15105550102?body=hello%20there"> sms:+15105550101,+15105550102?body=hello%20there </a>
sms://3490322111
<a href="sms://3490322111"> sms:// </a>
sms:15105550101?body=hello%20there
<a href="sms:15105550101?body=hello%20there"> sms: - body </a> <br/>
sms:15105550101;15105550102?body=hello%20there
<a href="sms:15105550101;15105550102?body=hello%20there"> sms: - body </a>
有2个?号,会出什么情况呢?
sms:15105550101;15105550102?body=hello%20th?ere
<a href="sms:15105550101;15105550102?body=hello%20th?ere"> sms: - body </a>
有多于一个?号,看看怎么样
sms:+15105550101;15105550102?body=hello%20th?ere?hahahah?ahhaha
<a href="sms:+15105550101;15105550102?body=hello%20th?ere?hahahah?ahhaha"> sms: - body </a>
如果链接中带中文,而不是encode为UTF-8的字符怎么办?
sms:+15105550101?body=hello,你好,我是宋史超
<a href="sms:+15105550101?body=hello,你好,我是宋史超"> 带中文 </a>
</pre>
</body>
</html>
第二:tel:
其实和tel协议相关的还有一个协议:wtai,这个协议是在wap页面使用的,类似tel协议。具体自行百度。
打电话模式包括:
1.调用空的Dial拔号。
2.调用Dial并传递号码。
3.直拔。
1.调用空的Dial拔号。
2.调用Dial并传递号码。
3.直拔。
(In general, a "+" symbol in E.164 indicates that an international prefix is required.)
一,语法:tel:<phonenumber>
二,Wireless Telephony Application Interface
wtai://wp/mc/+18165551212
. Examples
tel:+1-201-555-0123: This URI points to a phone number in the United States. The hyphens are included to make the number more human readable; they separate country, area code and subscriber number. tel:7042;phone-context=example.com: The URI describes a local phone number valid within the context "example.com". tel:863-1234;phone-context=+1-914-555: The URI describes a local phone number that is valid within a particular phone prefix.
参考连接:
http://tools.ietf.org/html/rfc3966
第三:mailto:
mailto:协议可以带很多参数,比如subject, cc, bcc, body 等。但是要求对应的邮件客户端也支持的很好才可以。
mailto:421271944@qq.com?subject=a%20test&body=my%20idea%20test
4.
<a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
5.Using "mailto" within a HTML document to generate a link for sending email:
<a href="mailto:someone@example.com">Send email</a>
6.It is also possible to specify initial values for headers (e.g. subject, cc, etc.) and message body in the URL. Blanks, carriage returns, and linefeeds cannot be embedded but must be percent-encoded.
<a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
<a href="mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body">Send email</a>
7.Multiple addresses can also be specified:[citation needed]
mailto:someone@example.com,someoneelse@example.com
<a href="mailto:someone@example.com,someoneelse@example.com">Send email</a>
<a href="mailto:someone@example.com,someoneelse@example.com">Send email</a>
8.The address can also be omitted:
<a href="mailto:?to=&subject=mailto%20with%20examples&body=http://en.wikipedia.org/wiki/Mailto">Share this knowledge...</a>
9. mailto:someone@example.com,someoneelse@example.com?to=421@qq.com&cc=sfksjfks@qq.com&bcc=sjfkd@qq.com&subject=test%20subject&body=test%20body
<a href="mailto:?to=&subject=mailto%20with%20examples&body=http://en.wikipedia.org/wiki/Mailto">Share this knowledge...</a>
9. mailto:someone@example.com,someoneelse@example.com?to=421@qq.com&cc=sfksjfks@qq.com&bcc=sjfkd@qq.com&subject=test%20subject&body=test%20body
10.mailto:?to=email%40example.com
参考连接(这几个链接非常好):
4.http://shadow2531.com/opera/testcases/mailto/modern_mailto_uri_scheme.html
2013年10月24号更新:
发送邮件支持多联系人,cc, bcc, body, subject等等,开始只是用Uri.parse(url)这样的方式,但是发现原生的邮箱对这个支持的不好,想到一中新的办法,把这些发送的内容都写到intent的extra中,这样就对应了。具体可参考下面两篇文章:
http://ask.youkuaiyun.com/questions/475
http://www.2cto.com/kf/201109/103814.html
2013年10月24号更新:
发送邮件支持多联系人,cc, bcc, body, subject等等,开始只是用Uri.parse(url)这样的方式,但是发现原生的邮箱对这个支持的不好,想到一中新的办法,把这些发送的内容都写到intent的extra中,这样就对应了。具体可参考下面两篇文章:
http://ask.youkuaiyun.com/questions/475
http://www.2cto.com/kf/201109/103814.html
第四:intent: 协议
第一次听说这个协议,android的动作就是通过intent实现的。那么inent: 协议到底是什么呢?疯狂的百度一番发现,在chrome for android的介绍页面中很重要的位置做了说明。
这里有语法说明,有实例,非常好,然后我自己写了很多测试的例子。
然后还看到和intent:// 相关的就是在百度地图的API中了。不得不说,百度地图的实现方式,非常棒的。参看链接:
http://developer.baidu.com/map/uri-introandroid.htm
我自己写的intent:协议测试的例子:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<pre>
intent:
have segment:这样就能吊起应用,如果没有安装,会调起应用商店
<a href="intent://map/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&src=xxx|Browserxx#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end"> intent: </a>
NO segment:这样就是找不到网页
<a href="intent://map/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&src=xxx|Browserxx"> intent: </a>
移动APP调起Android百度地图方式举例
intent = Intent.getIntent("intent://map/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&src=yourCompanyName|yourAppName#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
startActivity(intent);
网页应用调起Android百度地图方式举例
bdapp://map/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&src=yourCompanyName|yourAppName
<a href="bdapp://map/marker?location=40.047669,116.313082&title=我的位置&content=百度奎科大厦&src=yourCompanyName|yourAppName">地图标点</a>
zxing --->
这样的话,如果安装就吊起应用,没安装就会吊起系统内的应用商店
To launch the Zxing barcode scanner app, you encode your href on the anchor as follows:
intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end
<a href="intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end"> Take a QR code </a>
这样的话,如果没有安装,就显示打不开网页
<a href="zxing://scan/"> zxing://scan/ </a>
</pre>
<pre>
intent://market/details/com.tecent.qq#Intent;scheme=market;package=com.xiaomi.market;end
<a href="intent://details?id=com.tencent.mobileqq#Intent;scheme=market;package=com.xiaomi.market;end"> details?id=com.tencent.mobileqq </a>
intent://search?q=pname:com.tencent.mobileqq#Intent;scheme=market;package=com.xiaomi.market;end
<a href="intent://search?q=pname:com.tencent.mobileqq#Intent;scheme=market;package=com.xiaomi.market;end"> search?q=pname:com.tencent.mobileqq </a>
------>这种格式是不对的,会直接调起应用市场,如果选择小米应用商店后,会调到搜索页面,然后输入框是:pname:com.xiaomi.market
总结一下,就是不能在intent://后加scheme,而写在后面的fragment中
intent://market/search?q=pname:com.tencent.mobileqq#Intent;scheme=market;package=com.xiaomi.market;end
<a href="intent://market/search?q=pname:com.tencent.mobileqq#Intent;scheme=market;package=com.xiaomi.market;end"> market/search?q=pname:com.tencent.mobileqq </a>
intent://5555#Intent;scheme=sms;package=com.android.mms;end
<a href="intent://5555#Intent;scheme=sms;package=com.android.mms;end"> 5555 </a>
---- ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=intent://5555 }
<a href="intent://scan#Intent;scheme=myapp;package=com.example.schematest1;end">myapp test </a>
host 填 host=scan 的时候,下面这2种这样会吊起应用商店, 但是当host填空时,就能直接掉起 app
<a href="intent://#Intent;scheme=myapp;package=com.example.schematest1;end">myapp test </a>
<a href="intent://?#Intent;scheme=myapp;package=com.example.schematest1;end">myapp test </a>
这样的data是不正确的:Intent { act=android.intent.action.VIEW dat=// pkg=com.example.schematest1 }
<a href="intent://#Intent;package=com.example.schematest1;end">myapp test </a>
component=com.example.schematest1.MainActivity
<a href="intent://#Intent;component=com.example.schematest1/.MainActivity;package=com.example.schematest1;end"> test 00 </a>
<a href="intent:#Intent;scheme=myapp;action=com.test.custom.action;package=com.example.schematest1;end"> action </a>
测试broadcast receiver action,but fail
<a href="intent:#Intent;scheme=myapp;action=com.myaction.myapp;package=com.example.schematest1;end"> action 22 </a>
这样可以调起来
<a href="myapp://scan"> myapp:// </a>
测试action,这样不行,调起应用商店
<a href="intent://#Intent;action=com.myaction.myapp;package=com.example.schematest1;end">myapp test </a>
1.这个不行,安装了豆瓣电影,还是吊起应用商店
intent://doubanmovie?#Intent;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;component=com.douban.movie/.SeatActivity;data=24008809;end
<a href="intent://doubanmovie?#Intent;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;package=com.douban.movie;end"> 111 </a>
和上面的效果一样,都是吊起应用商店
<a href="intent://?#Intent;action=android.intent.action.VIEW;package=com.douban.movie;end"> 222 </a>
3.这个可以掉起应用商店
intent://doubanmovie?#intent;scheme=doubanmovie;action=com.douban.movie;component=com.douban.movie/.SeatActivity;end
<a href="intent://doubanmovie?#Intent;scheme=doubanmovie;action=com.douban.movie;component=com.douban.movie/.SeatActivity;package=com.douban.movie;end"> 333 </a>
下面这几个,没有data的都能掉起应用商店
这个调不起来
<a href="intent://?body=hello#Intent;scheme=sms;data=sms://3490322111;package=com.android.mms;end"> 111 </a>
这个没有data,能进入sms,但是有 //
<a href="intent://?body=hello#Intent;scheme=sms;package=com.android.mms;end"> 222 </a>
这个有data,掉不起来
<a href="intent://#Intent;scheme=sms;data=555;package=com.android.mms;end"> 333 </a>
这个能进入SMS,但是有 //
<a href="intent://#Intent;scheme=sms;package=com.android.mms;end"> 444 </a>
这个完全没问题哦
<a href="intent:555?body=hello#Intent;scheme=sms;package=com.android.mms;end"> 555 </a>
这个能进入,但是有 //
<a href="intent://555?body=hello#Intent;scheme=sms;package=com.android.mms;end"> 666 </a>
能进入,但是有 //+
<a href="intent://+555#Intent;scheme=sms;package=com.android.mms;end"> 777 </a>
能进入,但是 //+address=555
<a href="intent://address=555?body=hello#Intent;scheme=sms;package=com.android.mms;end"> 888 </a>
创建的 Intent 的实例默认 category 就包含了 Intent.CATEGORY_DEFAULT ,google 这样做的原因是为了让这个 Intent 始终有一个 category。
</body>
</html>
结尾
暂时学习到这里,下面放一些搜索过的链接,感觉对理解蛮有用的。
http://stackoverflow.com/search?q=intent%3A%2F%2Fscan%2F%23Intent%3Bscheme%3Dzxing%3Bpackage%3Dcom.google.zxing.client.android%3Bend
http://stackoverflow.com/questions/8254887/calling-phone-sms-api-by-use-of-phonegap-using-javascript
http://stackoverflow.com/questions/2430045/how-to-register-some-url-namespace-myapp-app-start-for-accessing-your-progr/2430468#2430468
http://stackoverflow.com/questions/5065982/android-custom-url-to-open-app-like-in-ios
http://stackoverflow.com/questions/15554029/how-do-i-open-any-app-from-my-web-browser-chrome-in-android-what-do-i-have-to/15597586#15597586
http://stackoverflow.com/questions/15341855/chrome-25-iframe-customize-protocol-don-twork/15441069#15441069