【问题标题】:I want to start UBER/LYFT app to get it into foreground from my app我想启动 UBER/LYFT 应用程序以使其从我的应用程序进入前台
【发布时间】:2018-11-14 01:47:42
【问题描述】:

我正在编写一个应用程序,以便在我的应用程序中使用浮动按钮访问 uber/lyft 应用程序。

基本上我会有两个浮动按钮,一个用于 Uber,另一个用于 Lyft。当我点击 Uber 浮动按钮时,我想在前台启动或获取 Uber 应用程序,当我点击 Lyft 浮动按钮时,启动 Lyft 应用程序或将其置于前台。

我使用什么 Activity 参数来实现这一点?

我在智能手机上使用 Android Oreo。

【问题讨论】:

    标签: android android-activity uber-api lyft-api


    【解决方案1】:

    只需在 Google Play 上查找这些应用的软件包名称即可。 它应该在地址栏中。 然后使用类似这样的东西来启动它们:

    Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
    if (launchIntent != null) { 
        startActivity(launchIntent);//null pointer check in case package name was not found
    }
    

    扩展这个,下面的代码可以让你启动一个应用,或者带你去 google play 下载它:

    public void startNewActivity(Context context, String packageName) {
        Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
        if (intent == null) {
            // Bring user to the market or let them choose an app?
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=" + packageName));
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-11-28
      • 1970-01-01
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多