您当前的位置: 首页 >  android

韩曙亮

暂无认证

  • 0浏览

    0关注

    1068博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【Google Play】从 Android 应用中跳转到 Google Play 中 ( 跳转代码示例 | Google Play 页面的链接格式 | Google Play 免安装体验 )

韩曙亮 发布时间:2022-01-10 16:57:52 ,浏览量:0

文章目录
  • 前言
  • 一、从 Android 应用跳转到 Google Play 代码
  • 二、Google Play 页面的链接格式
  • 三、Google Play 免安装体验

前言

本博客参考资料

  • 链接到 Google Play : https://developer.android.google.cn/distribute/marketing-tools/linking-to-google-play.html 官方文档 ;
一、从 Android 应用跳转到 Google Play 代码

首先 , 创建 Intent , 设置其 Action 为 “android.intent.action.VIEW” ,

	/**
	 * 活动操作:向用户显示数据。这是最常见的
	 * 对数据执行的操作——这是可以对数据执行的通用操作
	 * 获取最合理事件发生的一段数据。例如
	 * 在联系人条目上使用时,它将查看该条目;当在机器上使用时
	 * mailto:URI 它将弹出一个充满信息的由URI提供的撰写窗口.
	 * 当与 tel:URI 一起使用时,它将调用拨号器。
	 * 

输入:{@link#getData}是从中检索数据的URI。 *

输出:无。 */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_VIEW = "android.intent.action.VIEW";

然后 , 设置 Uri 操作数据 , 该 Uri 就是对应的 Google Play 页面链接 ;

	/**
	 * 设置此意图操作的数据。这种方法是自动的
	 * 清除以前由{@link#setType} 或
	 * {@link#setTypeAndNormalize} 设置的内容。
	 * 
	 * 

注意:Android框架中的方案匹配是 * 区分大小写,与正式RFC不同。因此 * 您应该始终使用小写方案编写Uri, * 或者使用{@linkuri#normalizeScheme}或者 * {@link#setDataAndNormalize} * 确保方案转换为小写 * * @param data 此意图现在针对的数据的Uri。 * * @return 返回相同的Intent对象,用于链接多个调用 * 变成一句话。 * * @see #getData * @see #setDataAndNormalize * @see android.net.Uri#normalizeScheme() */ public @NonNull Intent setData(@Nullable Uri data) { mData = data; mType = null; return this; }

最后 , 设置一个明确的应用程序包名 , 设置 “com.android.vending” 包名可以在跳转后直接显示 Google Play 对应的页面 , 不再弹出选择器 ; 否则打开时 , 会显示应用的选择器 ;

	/**
	 * (通常是可选的)设置一个明确的应用程序包名称,该名称限制此意图将解析到的组件。
	 * 如果保留默认值null,则将考虑所有应用程序中的所有组件。
	 * 如果非null,则意图只能匹配给定应用程序包中的组件。
	 * 
	 * @param packageName要处理的应用程序包的名称
	 * 或null以允许任何应用程序包。
	 * 
	 * @return返回相同的Intent对象,用于链接多个调用
	 * 变成一句话。
	 * 
	 * @see#getPackage
	 * @see#resolveActivity
	 */
    public @NonNull Intent setPackage(@Nullable String packageName) {
        if (packageName != null && mSelector != null) {
            throw new IllegalArgumentException(
                    "Can't set package name when selector is already set");
        }
        mPackage = packageName;
        return this;
    }

代码示例 :

  • Kotlin :
val intent = Intent(Intent.ACTION_VIEW).apply {
    data = Uri.parse(
            "https://play.google.com/store/apps/details?id=com.example.android")
    setPackage("com.android.vending")
}
startActivity(intent)
  • Java :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(
        "https://play.google.com/store/apps/details?id=com.example.android"));
intent.setPackage("com.android.vending");
startActivity(intent);

上述代码来自 链接到 Google Play - 从 Android 应用提供链接 地址 ;

二、Google Play 页面的链接格式

Google Play 页面的链接格式 :

  • 应用的商品详情页面 :
https://play.google.com/store/apps/details?id=
http://play.google.com/store/apps/details?id=com.google.android.apps.maps
  • 指定开发者页面 : 5700313618786177705 是指定的开发者 id ;
https://play.google.com/store/apps/dev?id=
https://play.google.com/store/apps/dev?id=5700313618786177705
  • 搜索结果页面 : 搜索 maps 内容 , c=apps 表示只在 Google Play 中搜索应用 ;
https://play.google.com/store/search?q=
http://play.google.com/store/search?q=maps&c=apps
  • 应用合集页面 : 常见的应用合集参考 https://developer.android.google.cn/distribute/marketing-tools/linking-to-google-play.html?hl=zh-cn#OpeningCollection 文档 ;
https://play.google.com/store/apps/collection/
http://play.google.com/store/apps/collection/topselling_free
  • 启动免安装应用 : 使用该链接的前提是对应 package_name 包名的应用必须是一款免安装应用 , 免安装应用开发参考 https://developer.android.google.cn/topic/google-play-instant 文章 ;
https://play.google.com/store/apps/details?id=&launch=true
三、Google Play 免安装体验

参考 Google Play Instant 文档 ;

关注
打赏
1663594092
查看更多评论
立即登录/注册

微信扫码登录

0.0720s