【发布时间】:2014-06-29 19:23:13
【问题描述】:
谁能告诉我从 Android 库项目与使用此库的应用程序进行通信的好方法?
一点说明:我的库接收 GCM 通知并使用此库将其中一些转发到应用程序。现在,我通过库发送的 Intent 和在 App 中监听该意图的 BroadcastReceiver 实现了这一点。
问题:当我使用我的应用程序安装 2 个应用程序时,两者都会收到对方的通知。有人出主意吗?
提前致谢!
[编辑]
这是一些代码。我在库中收到 GCM 通知并将其转发给消费应用:
GCMIntentService:
@Override
protected void onHandleIntent(Intent intent) {
...
String notificationString = intent
.getStringExtra(GCMConstants.NOTIFICATION);
Intent broadIntent = new Intent(getResources().getString(
R.string.con_broadcast_gcm_notification));
broadIntent.putExtra("callback", notification.getCallback());
context.sendBroadcast(broadIntent);
...
}
我的 BroadcastReceiver 监听 con_broadcast_gcm_notification。它通过 Intent-Filter 在清单中注册。
manifest.xml
...
<receiver android:name=".MyBroadcastReceiver" >
<intent-filter>
<action android:name="de.tuberlin.snet.gcm.notification" />
</intent-filter>
</receiver>
...
【问题讨论】: