android - 发送 Intent 到另一个应用程序而不在android中打开它

标签 android android-intent

我有两个应用程序,我想在按下按钮时从第一个应用程序启动第二个应用程序。但我不希望第二个出现在前面。它将在后台完成其工作。我怎样才能做到这一点?请给我一个指导。我尝试了这个,但它打开了应用程序并出现在前面,这不是我想要的

       Intent intent = getPackageManager().getLaunchIntentForPackage(
                "com.example.abc");
        if (intent == null) {
            Toast.makeText(this, R.string.app_not_found, Toast.LENGTH_SHORT)
                    .show();
        } else {
            intent .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent .putExtra("str", "str");
            startActivity(intent );
        }

提前致谢

最佳答案

您正在调用一个 Activity ,因此它将打开前面的 Activity 。您应该调用 BroadCastReceiver ,这将在后台打开。单击 Here,这就是我使用 BroadCastReceiver 完成的操作。

关于android - 发送 Intent 到另一个应用程序而不在android中打开它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20801074/

相关文章:

android - 无法使用 FileProvider 打开普通文本文件

Android 模拟器 - Intent.createChooser 在打开 pdf 类型文档时显示 "No application can perform this action"

android - 用于打开移动数据的 Intent ?

android - 把 EditText 像 iPhone UITextField

android - 访问 RecyclerViewAdapter 内的生命周期范围

Android.mk,包含所有 cpp 文件

android - 使用 backstack 启动 Activity

Android : After Callback from Facebook, 我的主要 Activity 将调用哪个状态?

android - 模拟器不启动(白屏)

android - IOS 中的 Android content provider 相当于什么?