我有 2 个应用程序,App1 和 App2
在 App1 中,清单文件的 BroadcastReceiverIncoming 定义如下。
<receiver android:name="packagename.BroadcastReceiverIncoming"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="packagename.BroadcastReceiverIncoming" />
</intent-filter>
</receiver>
BroadcastReceiverIncoming 在 App1 中定义。
现在在 App2 中,我调用它来调用广播接收器,但它现在以某种方式工作?
Intent intent = new Intent();
intent.setClassName("packageName", "packagename.BroadcastReceiverIncoming");
intent.setAction("packagename.BroadcastReceiverIncoming");
appContext.sendBroadcast(intent);
即使第 2 行已注释/未注释,它也不会调用 BroadcastReceiverIncoming。
如果我调用 BroadcastReceiverIncoming,则通过 adbadb shell am broadcast -n packageName/packagename.BroadcastReceiverIncoming
在 App1 中正确调用。