CarnivalとSmoochの両方で動作することができない理由は、両方のライブラリが独自のGcmListenerServiceを登録していることです。また、Androidでは、マニフェストで定義された最初のGcmListenerServiceがすべてのGCMメッセージを受け取ります。 Multiple GCM listeners using GcmListenerService
最善の解決策はただ1つのGcmListenerServiceの実装を持っている、との両方のために、このハンドルのメッセージを持っているだろう:あなたは、主にSOは、次の資料オフに基づいため
は、私は解決策を持っています。
独自のGcmListenerServiceを指定するには、Google's Cloud Messaging Documentationの指示に従ってください。
Smoochは、独自のGCM登録を無効にするために必要なツールを提供します。
そうするために、キスを初期化中に、単にsetGoogleCloudMessagingAutoRegistrationEnabled
を呼び出す:
Settings settings = new Settings("<your_app_token>");
settings.setGoogleCloudMessagingAutoRegistrationEnabled(false);
Smooch.init(this, settings);
そして、あなた自身のGcmRegistrationIntentService
で、あなたのトークンでSmooch.setGoogleCloudMessagingToken(token);
を呼び出します。
完了したら、GCMメッセージを希望のGCM受信者に渡すことができます。
@Override
public void onMessageReceived(String from, Bundle data) {
final String smoochNotification = data.getString("smoochNotification");
if (smoochNotification != null && smoochNotification.equals("true")) {
data.putString("from", from);
Intent intent = new Intent();
intent.putExtras(data);
intent.setAction("com.google.android.c2dm.intent.RECEIVE");
intent.setComponent(new ComponentName(getPackageName(), "io.smooch.core.GcmService"));
GcmReceiver.startWakefulService(getApplicationContext(), intent);
}
}
EDITはキスバージョン3.2.0の時点で、あなたは今より簡単onMessageReceivedにGcmService.triggerSmoochGcm
を呼び出してキスの通知をトリガすることができます。
@Override
public void onMessageReceived(String from, Bundle data) {
final String smoochNotification = data.getString("smoochNotification");
if (smoochNotification != null && smoochNotification.equals("true")) {
GcmService.triggerSmoochGcm(data, this);
}
}
Smoochがこれを行うことができます。残念ながら私はカーニバルはしないと確信しています。しかし、私は同じアプローチを使用し、各サービスで 'startWakefulService'を2回呼び出すことができ、私の中継インテントサービスがマニフェストの最初にリストされていることを確認する必要があります。これを試してここで更新します。 –
これは機能します。両方のサービスで同じ送信者IDとAPIキーを使用しているため、GCM登録を無効にする必要はありません。また、smoochNotificationフラグを使用してメッセージを適切な場所に送信することもできます。だから、すべての良い...ありがとう! –