Android 打开应用商店评分

最近处理华为渠道包,打开应用商店评分系统,简单整理一下跳转商店的代码,以便将来翻看

国内应用商店跳转

跳转华为应用商店进行评分
先判断设备是否安装应用商店,如果没有安装应用商店,则跳转至对应的网页进行下载
注:appId 是在华为控制台创建应用的id

注:appId 是在华为控制台创建应用的id
public static void openHmsStore ( ) {
	requestHmsStoreReviewLeve("com.huawei.appmarket");
}
    public static void requestHmsStoreReviewLeve(final String marketPkg)
    {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    String appPkg = activity.getPackageName();
                    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);

                    if (intent.resolveActivity(activity.getPackageManager()) == null) {
                        uri = Uri.parse("https://appstore.huawei.com/app/C" + appId);
                        intent = new Intent(Intent.ACTION_VIEW, uri);
                    }
                    activity.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

常见应用商店marketPkg name参考:https://blog.csdn.net/Mr___Xu/article/details/101220574

谷歌商店跳转

谷歌商店通过url地址进行跳转,如果设备安装商店APP会自动跳转到商店,没有安装商店则跳转到网页

public static void openGooglePlayStore ( ) {
	showGooglePlayStore();
}
    public static void showGooglePlayStore()
    {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            	String appPkg = activity.getPackageName();
            	String url = "http://play.google.com/store/apps/details?id=" + appPkg;
                Log.d(TAG, "rate url :" + url);
                activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            }
        });
    }

苹果商店跳转

if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.3f)
        {
            [SKStoreReviewController requestReview];
            return;
        }
        
        NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@?action=write-review", appId];    
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

猜你喜欢

转载自blog.csdn.net/u011484013/article/details/105855219