0

我有一个 Android 应用程序,我在其中实现了一项服务,该服务已在 Android Manifest 中声明为“已导出”。此设备上安装了许多不同的应用程序,它们试图启动此导出的服务。他们都使用此代码来启动导出的服务:

    MY_ACTION = "com.phantom.foobar.action.xyz"
    PACKAGE_NAME = "com.phantom.foobar"
    CLASS_NAME = "com.phantom.foobar.IpcService"  


    public static void startSaveUrlAction(Context context, String foo, String bar) {
        Intent intent = new Intent(MY_ACTION);
        intent.setClassName(PACKAGE_NAME, CLASS_NAME);
        intent.putExtra(FOO, foo);
        intent.putExtra(BAR, bar);
        context.startService(intent);
    }

Manifest 文件中应用程序标签内的服务描述:

<service
    android:name=".IpcService"
    android:exported="true" />

现在的问题是一些应用程序能够启动它,而有些则不能。以下是无法启动该服务的应用程序的 logcat 信息:

01-02 16:04:05.574  1385  2698 W ActivityManager: Unable to start service Intent { cmp=another.music.player/com.phantom.foobar.IpcService } U=0: not found
01-02 16:04:05.575  1385  2699 W ActivityManager: Unable to start service Intent { cmp=another.music.player/com.phantom.foobar.IpcService } U=0: not found

如果我没记错的话,{ cmp=another.music.player/com.phantom.foobar.IpcService }这是一个由{ cmp = package_name/class_name }. 即使我已指定PACKAGE_NAME为,com.phantom.foobar但它试图开始错误的意图。在这种情况下,another.music.player是尝试启动导出服务的应用程序的包名称。

这只发生在某些应用程序中。我想知道为什么会这样。是否有任何属性或某些东西(可以在 Android Manifest 中设置的某种属性)可以阻止应用程序在包外启动意图?

抽象细节:

我正在使用 Xposed 框架,它允许我挂钩其他应用程序的方法。我已经从 Android API 中挂钩了一个方法。现在,每当在其他应用程序中调用该方法时,我都会从该应用程序中提取一些信息并使用它的上下文,我开始导出 IntentService com.phantom.foobar,因此使用上面给定的函数将信息传递给我的应用程序。

4

0 回答 0