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);
}
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。