App Indexing
2015-08-28 17:39
405 查看
什么是App Indexing?
将网站上的网页和智能手机相关联。已安装了相应软件的用户可以通过网站直接打开应用内容。详细信息请参见官网https://developers.google.com/app-indexing/webmasters/app
官网上写的非常详细,可以看中文的。
代码实现
HTML网页中要提供App Indexing的网址是http://example.com/淘宝店铺ID。淘宝店铺ID是不确定的值。在AndroidMenifest.xml中声明Intent过滤器。
<activity android:name="com.example.android.GizmosActivity" android:label="@string/title_gizmos" > <intent-filter android:label="@string/filter_title_viewgizmos"> <action android:name="android.intent.action.VIEW" /> <!-- 可以获取包含 "http://example.com/g23422" 开头的url --> <data android:scheme="http" android:host="example.com" android:pathPrefix=".*" <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity>
可以使用下面两种方式测试是否能跳转到淘宝店铺ID为【g23422】的app页面:
adb shell am start -a android.intent.action.VIEW -d "http://example.com/g23422" com.example.android
或者在HTML网页上添加:
<a href="intent://example.com/gizmos#Intent;scheme=http;package=com.example.android;end;"> http://example.com/g23422 </a>
App Indexing的测试方法
在https://developers.google.com/app-indexing/webmasters/test中输入【android-app://packageName/scheme/host/pathPrefix】。详情请参考下图:如何判断应用从App Indexing进入的?
方法如下:public boolean isCallByAppIndexing(Activity activity) { Intent intent = activity.getIntent(); Uri uri = intent.getData(); if (uri != null) { String scheme = uri.getScheme(); String host = uri.getHost(); if (scheme != null && scheme.equals("http")) { if (host != null && host.equals("example.com")) { return true; } } } return false; }
获取淘宝店铺ID的方法:
public String getShopId(Activity activity) { String shopId = null; Uri uri = activity.getIntent().getData(); if (uri != null) { List<String> list = uri.getPathSegments(); shopId = (list == null ? null : list.get(0)); } return shopId; }
相关文章推荐
- iOS设计模式--迭代器模式
- iOS开发——创建你自己的Framework
- iOS中绘制圆形的函数方法
- Android的安全机制和su概述
- Android Outline,Shadow和Clip
- 关于安卓工程导出带res资源文件的jar的总结
- Android基础入门教程——5.2.1 Fragment实例精讲——底部导航栏的实现(方法1)
- Android Matrix
- Unity中物体跟随鼠标的位置
- Android自定义View的实现方法,带你一步步深入了解View(四)
- Android视图状态及重绘流程分析,带你一步步深入了解View(三)
- 【Android】 由ListView+ ViewHolder想到的
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- iOS中xib设置label等的圆角
- iOS URLWithString返回为空nil的解决方案
- Android Sqlite 使用 注意事项
- Scala学习笔记(七):Application特质
- cordova程序如何调适js-iOS平台-android平台
- hdu-5314 Happy King