我使用以下代码通过包名称链接到 Google Play、Amazon Appstore 和 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=";
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=";
public static void openOnMarket(String market, String web, Context context, String packageName) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(market + 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 + packageName));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
public static void openOnGooglePlayMarket(Context context, String packageName) {
openOnMarket(MARKET_GOOGLE_URL, WEB_GOOGLE_URL, context, packageName);
}
public static void openOnSamsungMarket(Context context, String packageName) {
openOnMarket(MARKET_SAMSUNG_URL, WEB_SAMSUNG_URL, context, packageName);
}
private static void openOnAmazonMarket(Context context, String packageName) {
openOnMarket(MARKET_AMAZON_URL, WEB_AMAZON_URL, context, packageName);
}
起初尝试通过URI打开市场应用程序,但如果找不到打开Web链接。我希望这段代码对某人有用。