修复跳转到华为商店问题

This commit is contained in:
hch 2023-12-08 15:32:18 +08:00
parent f8ac4617ed
commit 331b55a5ab

View File

@ -3,6 +3,7 @@ package com.yunbao.common.views;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
@ -114,7 +115,7 @@ public class APKUpdateCustomPopup extends CenterPopupView {
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) { } else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
//华为 //华为
//todo //todo
launchAppDetail(mContext, "com.pdlive.shayu", "com.pdlive.shayu"); launchAppDetail(mContext, "com.pdlive.shayu", "com.huawei.appmarket");
} else { } else {
versionImmediateUse.setVisibility(GONE); versionImmediateUse.setVisibility(GONE);
updateLine.setVisibility(VISIBLE); updateLine.setVisibility(VISIBLE);
@ -129,19 +130,31 @@ public class APKUpdateCustomPopup extends CenterPopupView {
}); });
} }
public static boolean isAppStoreExist(Context context) {
try {
PackageManager packageManager = context.getPackageManager();
packageManager.getPackageInfo("com.huawei.appmarket", PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
public static void launchAppDetail(Context mContext, String appPkg, String marketPkg) { public static void launchAppDetail(Context mContext, String appPkg, String marketPkg) {
try { try {
if (TextUtils.isEmpty(appPkg)) { if (TextUtils.isEmpty(appPkg)) {
return; return;
} }
if (isAppStoreExist(mContext)) {
Uri uri = Uri.parse("market://details?id=" + appPkg); Uri uri = Uri.parse("appmarket://details?id=" + appPkg);
Intent intent = new Intent(Intent.ACTION_VIEW, uri); Intent intent = new Intent(Intent.ACTION_VIEW, uri);
if (!TextUtils.isEmpty(marketPkg)) { if (!TextUtils.isEmpty(marketPkg)) {
intent.setPackage(marketPkg); intent.setPackage(marketPkg);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
} }
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }