-1

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

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

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

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

4

1 回答 1

0

只需在 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);
}
于 2018-11-14T02:23:50.167 回答