修复跳转到华为商店问题

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.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
@ -114,7 +115,7 @@ public class APKUpdateCustomPopup extends CenterPopupView {
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
//华为
//todo
launchAppDetail(mContext, "com.pdlive.shayu", "com.pdlive.shayu");
launchAppDetail(mContext, "com.pdlive.shayu", "com.huawei.appmarket");
} else {
versionImmediateUse.setVisibility(GONE);
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) {
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);
if (isAppStoreExist(mContext)) {
Uri uri = Uri.parse("appmarket://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);
mContext.startActivity(intent);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}