如果已安装我的应用程序,如何从另一个应用程序打开它;如果未安装,如何打开playstore?

时间:2018-12-02 04:43:45

标签: android android-intent

我试图在onclick列表器中从我的应用程序中打开另一个应用程序

val_3

它不起作用。

我想打开该应用程序(如果已安装)或在Playstore中打开(如果未安装)。

请帮助

1 个答案:

答案 0 :(得分:0)

Context ctx=this;
try {
    Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.example.app");
    ctx.startActivity(i);
} catch (Exception e) {
    try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://market.android.com/details?id=com.example.app")));
    } catch (android.content.ActivityNotFoundException anfe) {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.example.app")));
    }
}
相关问题