Android接收器-多个应用程序中接收器的名称和操作相同



假设我在2个应用程序(应用程序A和应用程序B)的清单中有以下接收器:

<receiver android:enabled="true" android:name="com.MyReceiver">
    <intent-filter>
        <action android:name="com.COMMON_ACTION" />
    </intent-filter>
</receiver>

在每个应用程序中,如果不存在,我想创建一个PendingIntent,并使用AlarmManager将其设置为不精确重复。为了检查是否存在,我执行以下代码:

boolean alarmExists = (PendingIntent.getBroadcast(mContext,
            DEFAULT_PENDING_INTENT_ID, intent,
            PendingIntent.FLAG_NO_CREATE) != null);

即使应用程序B已经在同一设备上创建了挂起的意图,这是否应该在应用程序A中返回false是否有理由推迟两个应用程序中的接收器(通过对每个应用程序使用不同的操作)?

每个应用程序都有自己的PendingIntent s。这些不在不同的应用程序之间共享。

如果应用程序A创建了ACTION="com.COMMON_ACTION"的PendingIntent,而应用程序B创建了:

Intent intent = new Intent("com.COMMON_ACTION");
boolean alarmExists = (PendingIntent.getBroadcast(mContext,
        DEFAULT_PENDING_INTENT_ID, intent,
        PendingIntent.FLAG_NO_CREATE) != null);

alarmExists将是false

最新更新