Android应用如何跳转到应用市场详情页面

Android应用开发过程中,可能会有需求,比如:推广时跳转到应用市场下载应用,跳转到应用市场给自己的应用打分,跳转到应用市场更新自己的应用。那如何跳转到应用市场呢?
可能跳转的方法大家都是知道的,方法如下:

public static void goToMarket(Context context, String packageName) {
    Uri uri = Uri.parse("market://details?id=" + packageName);
    Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
    try {
        context.startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
    }
}

在这里做个总结
直接代码贴出来

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;

import net.sqlcipher.database.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

/**
 * @类名称:MarketUtil
 * @单位:无
 * @联系人:朱世闯
 * @联系方式:[email protected]
 * @创建时间:2018/12/27-14:29
 * @功能描述:
 */
public class MarketUtil {
    private static final String TAG = "MarketUtil";

    public static List checkMarket(Context context) {
        List arrayList = new ArrayList();
        Intent intent = new Intent();
        intent.setAction("android.intent.action.MAIN");
        intent.addCategory("android.intent.category.APP_MARKET");
        int i = 0;
        List queryIntentActivities = context.getPackageManager().queryIntentActivities(intent, 0);
        int size = queryIntentActivities.size();
        while (i < size) {
            String str = ((ResolveInfo) queryIntentActivities.get(i)).activityInfo.packageName;
            String str2 = TAG;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("packageName : ");
            stringBuilder.append(str);
            Log.d(str2, stringBuilder.toString());
            arrayList.add(str);
            i++;
        }
        return arrayList;
    }

    public static boolean goToSamsungMarket(Context context, String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("http://www.samsungapps.com/appquery/appDetail.as?appId=");
        stringBuilder.append(str);
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuilder.toString()));
        intent.setPackage("com.sec.android.app.samsungapps");
        intent.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        try {
            context.startActivity(intent);
            return true;
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean goToSonyMarket(Context context, String str) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("http://m.sonyselect.cn/");
        stringBuilder.append(str);
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuilder.toString()));
        intent.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        try {
            context.startActivity(intent);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean to360Download(Context context, String str) {
        return toMarket(context, str, "com.qihoo.appstore");
    }

    public static boolean toMarket(Context context, String str, String str2) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("market://details?id=");
        stringBuilder.append(str);
        Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(stringBuilder.toString()));
        intent.addFlags(SQLiteDatabase.CREATE_IF_NECESSARY);
        if (str2 != null) {
            intent.setPackage(str2);
        }
        try {
            context.startActivity(intent);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    public static boolean toMeizu(Context context, String str) {
        return toMarket(context, str, "com.meizu.mstore");
    }

    public static boolean toQQDownload(Context context, String str) {
        return toMarket(context, str, "com.tencent.android.qqdownloader");
    }

    public static boolean toWandoujia(Context context, String str) {
        return toMarket(context, str, "com.wandoujia.phoenix2");
    }

    public static boolean toXiaoMi(Context context, String str) {
        return toMarket(context, str, "com.xiaomi.market");
    }

你可能感兴趣的:(Android应用如何跳转到应用市场详情页面)