App Indexing

什么是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;
    }


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值