qomg

qomg

enjoy life

Android打开应用商店

打开指定应用

private void openPlayStore(String packageName) {
  Intent playStoreIntent = new Intent(
    Intent.ACTION_VIEW,
    Uri.parse("market://details?id=" + packageName)
  // 打开instant应用
  // Uri.parse("market://launch?id=" + packageName)
  );
  setFlags(playStoreIntent);
  try {
    startActivity(playStoreIntent);
  } catch (Exception e) {
    Intent webIntent = new Intent(
      Intent.ACTION_VIEW,
      Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)
      // 打开instant应用
      // Uri.parse("https://play.google.com/store/apps/details?id=" + packageName + "&launch=true")
    );
    setFlags(webIntent);
    startActivity(webIntent);
  }
}

@SuppressWarnings("deprecation")
private void setFlags(Intent intent) {
  intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
  } else {
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  }
}

搜索应用(指定发布者)

String urlApp = "market://search?q=pub:Google+Inc.";
String urlWeb = "http://play.google.com/store/search?q=pub:Google+Inc.";
try {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlApp));
    setFlags(i);
    startActivity(i);
} catch (android.content.ActivityNotFoundException anfe) {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(urlWeb)));
    setFlags(i);
    startActivity(i);
}
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。