Android 跳转至各大应用商店应用详情页

2024-09-07 09:28

本文主要是介绍Android 跳转至各大应用商店应用详情页,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

测试通过机型品牌:
华为、小米、红米、OPPO、一加、Realme、VIVO、IQOO、荣耀、魅族、三星

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.TextUtils;
import com.joyssom.common.utils.ZLog;public class MarketUtils {private static MarketUtils tools;private static final String schemaUrl = "market://details?id=";public static MarketUtils getTools() {if (null == tools) {tools = new MarketUtils();}return tools;}/***/* 不指定包名/* @param mContext*/public boolean startMarket(Context mContext) {String packageName = mContext.getPackageName();//得到包名return startMarket(mContext, packageName);}/*** /* 指定包名* <p>* /** <p>* /* @param mContext* <p>* /* @param packageName*/public boolean startMarket(Context mContext, String packageName) {try {String deviceBrand = getDeviceBrand();//获得手机厂商//根据厂商获取对应市场的包名String brandName = deviceBrand.toUpperCase();//大写if (TextUtils.isEmpty(brandName)) {ZLog.e("没有读取到手机厂商~~");return false;}String marketPackageName = getBrandName(brandName);ZLog.d("marketPackageName:" + marketPackageName);ZLog.d("brandName:" + brandName);ZLog.d("deviceBrand:" + deviceBrand);if (null == marketPackageName || "".equals(marketPackageName)) {return false;}if (marketPackageName.equals(MarketUtils.PACKAGE_NAME.SAMSUNG_PACKAGE_NAME)) {//三星特殊处理Uri uri = Uri.parse("http://www.samsungapps.com/appquery/appDetail.as?appId=" + packageName);Intent goToMarket = new Intent();goToMarket.setClassName("com.sec.android.app.samsungapps", "com.sec.android.app.samsungapps.Main");goToMarket.setData(uri);try {mContext.startActivity(goToMarket);return true;} catch (ActivityNotFoundException e) {return false;}} else {return startMarket(mContext, packageName, marketPackageName);}} catch (ActivityNotFoundException anf) {ZLog.e("要跳转的应用市场不存在!" + anf.getMessage());} catch (Exception e) {ZLog.e("其他错误:" + e.getMessage());}return false;}/***/* 指定包名,指定市场/* @param mContext/* @param packageName/* @param marketPackageName*/public boolean startMarket(Context mContext, String packageName, String marketPackageName) {try {openMarket(mContext, packageName, marketPackageName);return true;} catch (ActivityNotFoundException anf) {ZLog.e("要跳转的应用市场不存在!" + anf.getMessage());return false;} catch (Exception e) {ZLog.e("其他错误:" + e.getMessage());return false;}}/***/* 打开应用市场/* @param mContext/* @param packageName/* @param marketPackageName*/private boolean openMarket(Context mContext, String packageName, String marketPackageName) {try {Uri uri = Uri.parse(schemaUrl + packageName);Intent intent = new Intent(Intent.ACTION_VIEW, uri);intent.setPackage(marketPackageName);intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);mContext.startActivity(intent);return true;} catch (ActivityNotFoundException anf) {ZLog.e("要跳转的应用市场不存在!" + anf.getMessage());return false;} catch (Exception e) {ZLog.e("其他错误:" + e.getMessage());return false;}}/***/* 检测是否是应用宝或者是百度市场/* @param mContext/* @param packageName/* @return*/private boolean isCheckBaiduOrYYB(Context mContext, String packageName) {boolean installed = isInstalled(packageName, mContext);return installed;}/****/* 检查APP是否安装成功/* @param packageName/* @param context/* @return*/private boolean isInstalled(String packageName, Context context) {if ("".equals(packageName) || packageName.length() <= 0) {return false;}PackageInfo packageInfo;try {packageInfo = context.getPackageManager().getPackageInfo(packageName, 0);} catch (PackageManager.NameNotFoundException e) {packageInfo = null;}if (packageInfo == null) {return false;} else {return true;}}private String getBrandName(String brandName) {if (BRAND.HUAWEI_BRAND.equals(brandName)) {//华为return PACKAGE_NAME.HUAWEI_PACKAGE_NAME;} else if (BRAND.OPPO_BRAND.equals(brandName)) {//opporeturn PACKAGE_NAME.OPPO_PACKAGE_NAME;} else if (BRAND.REALME_BRAND.equals(brandName)) {//realmereturn PACKAGE_NAME.OPPO_PACKAGE_NAME;} else if (BRAND.VIVO_BRAND.equals(brandName)) {//vivoreturn PACKAGE_NAME.VIVO_PACKAGE_NAME;} else if (BRAND.XIAOMI_BRAND.equals(brandName)) {//小米return PACKAGE_NAME.XIAOMI_PACKAGE_NAME;} else if (BRAND.REDMI_BRAND.equals(brandName)) {//红米return PACKAGE_NAME.XIAOMI_PACKAGE_NAME;} else if (BRAND.LENOVO_BRAND.equals(brandName)) {//联想return PACKAGE_NAME.LIANXIANG_PACKAGE_NAME;} else if (BRAND.MEIZU_BRAND.equals(brandName)) {//魅族return PACKAGE_NAME.MEIZU_PACKAGE_NAME;} else if (BRAND.HONOR_BRAND.equals(brandName)) {//荣耀return PACKAGE_NAME.HONOR_PACKAGE_NAME;} else if (BRAND.ZTE_BRAND.equals(brandName)) {//ztereturn PACKAGE_NAME.ZTE_PACKAGE_NAME;} else if (BRAND.NIUBIA_BRAND.equals(brandName)) {//努比亚return PACKAGE_NAME.NIUBIA_PACKAGE_NAME;} else if (BRAND.ONE_PLUS_BRAND.equals(brandName)) {//OnePlusreturn PACKAGE_NAME.OPPO_PACKAGE_NAME;} else if (BRAND.SONY_BRAND.equals(brandName)) {//索尼return PACKAGE_NAME.GOOGLE_PACKAGE_NAME;} else if (BRAND.SAMSUNG_BRAND.equals(brandName)) {return PACKAGE_NAME.SAMSUNG_PACKAGE_NAME;} else if (BRAND.GOOGLE_BRAND.equals(brandName)) {//googlereturn PACKAGE_NAME.GOOGLE_PACKAGE_NAME;}return "";}/*** /* 获取手机厂商*/private String getDeviceBrand() {return android.os.Build.BRAND;}public static class BRAND {public static final String HUAWEI_BRAND = "HUAWEI";//HUAWEI_PACKAGE_NAMEpublic static final String HONOR_BRAND = "HONOR";//HUAWEI_PACKAGE_NAMEpublic static final String OPPO_BRAND = "OPPO";//OPPO_PACKAGE_NAMEpublic static final String REALME_BRAND = "REALME";//OPPO_PACKAGE_NAMEpublic static final String MEIZU_BRAND = "MEIZU";//MEIZU_PACKAGE_NAMEpublic static final String VIVO_BRAND = "VIVO";//VIVO_PACKAGE_NAMEpublic static final String XIAOMI_BRAND = "XIAOMI";//XIAOMI_PACKAGE_NAMEpublic static final String REDMI_BRAND = "REDMI";//XIAOMI_PACKAGE_NAMEpublic static final String LENOVO_BRAND = "LENOVO";//LIANXIANG_PACKAGE_NAME //Lenovopublic static final String ZTE_BRAND = "ZTE";//ZTE_PACKAGE_NAMEpublic static final String XIAOLAJIAO_BRAND = "XIAOLAJIAO";//ZHUOYI_PACKAGE_NAMEpublic static final String QH360_BRAND = "360";//QH360_PACKAGE_NAMEpublic static final String NIUBIA_BRAND = "NUBIA";//NIUBIA_PACKAGE_NAMEpublic static final String ONE_PLUS_BRAND = "ONEPLUS";//OPPO_PACKAGE_NAMEpublic static final String MEITU_BRAND = "MEITU";//MEITU_PACKAGE_NAMEpublic static final String SONY_BRAND = "SONY";//GOOGLE_PACKAGE_NAMEpublic static final String GOOGLE_BRAND = "GOOGLE";//GOOGLE_PACKAGE_NAMEpublic static final String HTC_BRAND = "HTC";//未知应用商店包名public static final String ZUK_BRAND = "ZUK";//未知应用商店包名public static final String SAMSUNG_BRAND = "SAMSUNG";//未知应用商店包名}/** Redmi*//*** /* 华为,oppo,vivo,小米,360,联想,魅族,安智,百度,阿里,应用宝,goog,豌豆荚,pp助手**/public static class PACKAGE_NAME {public static final String OPPO_PACKAGE_NAME = "com.heytap.market";//oppopublic static final String VIVO_PACKAGE_NAME = "com.bbk.appstore";//vivopublic static final String HUAWEI_PACKAGE_NAME = "com.huawei.appmarket";//华为public static final String HONOR_PACKAGE_NAME = "com.hihonor.appmarket";//荣耀public static final String XIAOMI_PACKAGE_NAME = "com.xiaomi.market";//小米public static final String MEIZU_PACKAGE_NAME = "com.meizu.mstore";//,魅族public static final String LIANXIANG_PACKAGE_NAME = "com.lenovo.leos.appstore";//联想public static final String ZTE_PACKAGE_NAME = "zte.com.market";//ztepublic static final String GOOGLE_PACKAGE_NAME = "com.android.vending";//googlepublic static final String NIUBIA_PACKAGE_NAME = "com.nubia.neostore";//努比亚public static final String SAMSUNG_PACKAGE_NAME = "com.sec.android.app.samsungapps";}/*** /* 启动到应用商店app详情界面* <p>* /* @param appPkg 目标App的包名* <p>* /* @param marketPkg 应用商店包名 ,如果为"" 则由系统弹出应用商店* <p>* /* 列表供用户选择,否则调转到目标市场的应用详情界面,某些应用商店可能会失败*/public static void launchAppDetail(Context context, String appPkg, String marketPkg) {try {if (TextUtils.isEmpty(appPkg)) return;Uri uri = Uri.parse("market://details?id=" + appPkg);Intent intent = new Intent(Intent.ACTION_VIEW, uri);if (!TextUtils.isEmpty(marketPkg)) {intent.setPackage(marketPkg);}intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(intent);} catch (Exception e) {e.printStackTrace();}}
}

这篇关于Android 跳转至各大应用商店应用详情页的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144688

相关文章

将Python应用部署到生产环境的小技巧分享

《将Python应用部署到生产环境的小技巧分享》文章主要讲述了在将Python应用程序部署到生产环境之前,需要进行的准备工作和最佳实践,包括心态调整、代码审查、测试覆盖率提升、配置文件优化、日志记录完... 目录部署前夜:从开发到生产的心理准备与检查清单环境搭建:打造稳固的应用运行平台自动化流水线:让部署像

Linux中Curl参数详解实践应用

《Linux中Curl参数详解实践应用》在现代网络开发和运维工作中,curl命令是一个不可或缺的工具,它是一个利用URL语法在命令行下工作的文件传输工具,支持多种协议,如HTTP、HTTPS、FTP等... 目录引言一、基础请求参数1. -X 或 --request2. -d 或 --data3. -H 或

在Ubuntu上部署SpringBoot应用的操作步骤

《在Ubuntu上部署SpringBoot应用的操作步骤》随着云计算和容器化技术的普及,Linux服务器已成为部署Web应用程序的主流平台之一,Java作为一种跨平台的编程语言,具有广泛的应用场景,本... 目录一、部署准备二、安装 Java 环境1. 安装 JDK2. 验证 Java 安装三、安装 mys

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

Node.js 中 http 模块的深度剖析与实战应用小结

《Node.js中http模块的深度剖析与实战应用小结》本文详细介绍了Node.js中的http模块,从创建HTTP服务器、处理请求与响应,到获取请求参数,每个环节都通过代码示例进行解析,旨在帮... 目录Node.js 中 http 模块的深度剖析与实战应用一、引言二、创建 HTTP 服务器:基石搭建(一

Android数据库Room的实际使用过程总结

《Android数据库Room的实际使用过程总结》这篇文章主要给大家介绍了关于Android数据库Room的实际使用过程,详细介绍了如何创建实体类、数据访问对象(DAO)和数据库抽象类,需要的朋友可以... 目录前言一、Room的基本使用1.项目配置2.创建实体类(Entity)3.创建数据访问对象(DAO

java中VO PO DTO POJO BO DO对象的应用场景及使用方式

《java中VOPODTOPOJOBODO对象的应用场景及使用方式》文章介绍了Java开发中常用的几种对象类型及其应用场景,包括VO、PO、DTO、POJO、BO和DO等,并通过示例说明了它... 目录Java中VO PO DTO POJO BO DO对象的应用VO (View Object) - 视图对象

Go信号处理如何优雅地关闭你的应用

《Go信号处理如何优雅地关闭你的应用》Go中的优雅关闭机制使得在应用程序接收到终止信号时,能够进行平滑的资源清理,通过使用context来管理goroutine的生命周期,结合signal... 目录1. 什么是信号处理?2. 如何优雅地关闭 Go 应用?3. 代码实现3.1 基本的信号捕获和优雅关闭3.2

正则表达式高级应用与性能优化记录

《正则表达式高级应用与性能优化记录》本文介绍了正则表达式的高级应用和性能优化技巧,包括文本拆分、合并、XML/HTML解析、数据分析、以及性能优化方法,通过这些技巧,可以更高效地利用正则表达式进行复杂... 目录第6章:正则表达式的高级应用6.1 模式匹配与文本处理6.1.1 文本拆分6.1.2 文本合并6

python中的与时间相关的模块应用场景分析

《python中的与时间相关的模块应用场景分析》本文介绍了Python中与时间相关的几个重要模块:`time`、`datetime`、`calendar`、`timeit`、`pytz`和`dateu... 目录1. time 模块2. datetime 模块3. calendar 模块4. timeit