【问题标题】:Sending user to App. If App not exist send to playstore将用户发送到应用程序。如果 App 不存在发送到 playstore
【发布时间】:2018-09-18 16:48:43
【问题描述】:

我使用此代码将用户发送到另一个应用程序。如果他的手机上不存在该应用程序,我不希望用户将其发送到 Playstore。我正在寻找示例,但我没有找到任何东西。

// Launch My App one after clicking the button1
public void launchAppOne(View view) {
    Intent launchAppOne= getPackageManager().getLaunchIntentForPackage("com.app.android.myapp1");
    startActivity(launchAppOne);
}
// Launch My A after clicking the button2
public void launchAppTwo(View view) {
    Intent launchAppTwo = getPackageManager().getLaunchIntentForPackage("com.app.android.myapp2");
    startActivity(launchAppTwo);
}

【问题讨论】:

    标签: java android-studio android-intent start-activity


    【解决方案1】:

    您可以使用此代码。它会尝试启动应用程序,如果它不存在,则会打开应用程序的 Playstore 页面。

    String packageName = "org.mozilla.firefox";
    Intent intent= getPackageManager().getLaunchIntentForPackage(packageName);
    if (intent != null){
        startActivity(intent);
    }else{
        try {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)));
        }catch (android.content.ActivityNotFoundException anfe) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 2012-12-01
      • 2020-09-15
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多