在参与项目过程,客户提出要像Iphone那样,通过点击邮件里面的连接来启动APP:
起初在网上不断的search,找到了两个比较有用的回答:
http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser
http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app
总结了一下,解决方案如下:
1.
需要在点击链接时,启动的Activity下添加下面的filter
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"></category>
<!-- 指定启动APP的schema和host,强烈建议使用http等公开的schema,自定义的schema可能无法被邮件等视为超链接 -->
<data android:scheme="http" android:host="bizconf.mobile.com" />
</intent-filter>
然后我们就可以在邮件等内容中发送超链接
http://bizconf.mobile.com/xxxx
点击链接后,就会弹出让我们选择哪个程序启动(一般是浏览器和我们自己的程序),点击我们的程序启动就OK了。
2.点击链接时,获取链接中附带的数据:
http://twitter.com/status/1234
:
Uri data = getIntent().getData();
String scheme = data.getScheme(); // "http"
String host = data.getHost(); // "twitter.com"
List<String> params = data.getPathSegments();
String first = params.get(0); // "status"
String second = params.get(1); // "1234"
如果大家有其他好的实现方法,欢迎分享~