写了一个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();
}
}
}
05-03 23:20