只需使用以下代码。它首先尝试通过URI打开市场应用程序,但如果找不到,则打开Web链接。
public static final String MARKET_AMAZON_URL = "amzn://apps/android?p=";
public static final String WEB_AMAZON_URL = "http://www.amazon.com/gp/mas/dl/android?p=";
private static void openOnAmazonMarket(Context context, String packageName) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MARKET_AMAZON_URL + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(WEB_AMAZON_URL + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
对于Google Play和Samsung Galaxy Apps的链接如下:
public static final String MARKET_GOOGLE_URL = "market://details?id=";
public static final String WEB_GOOGLE_URL = "http://play.google.com/store/apps/details?id=";
public static final String MARKET_SAMSUNG_URL = "samsungapps://ProductDetail/";
public static final String WEB_SAMSUNG_URL = "http://www.samsungapps.com/appquery/appDetail.as?appId=";