Android 接收者 - 多个应用程序中接收者的名称和操作相同
Android receivers - Same name and action of receiver in multiple apps
假设我在 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 中是否应该 return 为假? 是否有理由延迟两个应用程序中的接收器(通过对每个应用程序使用不同的操作)?
每个应用程序都有自己的 PendingIntent
。这些不在不同的应用程序之间共享。
如果应用程序 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
。
假设我在 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 中是否应该 return 为假? 是否有理由延迟两个应用程序中的接收器(通过对每个应用程序使用不同的操作)?
每个应用程序都有自己的 PendingIntent
。这些不在不同的应用程序之间共享。
如果应用程序 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
。