Android应用市场的帮助类

写了一个Android应用市场的帮助类,如下:

public class MarketUtils {
    
    public static final String MARKET_DATA = "market://details";

    //判断应用市场是否存在
    public static boolean isMarketAvailable(Context context) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(MARKET_DATA));
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, 0);
        if (list != null && list.size() > 0) {
            return true;
        }
        return false;
    }

    //跳转到应用市场
    public static void gotoMarket(Context context, String appPackageName, String marketPackageName) {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(String.format("%s?id=%s", MARKET_DATA, appPackageName)));
            if (!TextUtils.isEmpty(marketPackageName)) {
                intent.setPackage(marketPackageName);
            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

posted @ 2019-04-17 20:12  南极冰川雪  阅读(232)  评论(0编辑  收藏  举报