我在我的Android应用程序中使用GCM推送通知服务。现在,我必须在我的Android应用程序中同时使用parse和GCM推送通知。但是,我没有收到GCM和Parse的通知(可能是由于冲突)。我可以单独到达GCM和Parse,但从不在一起,我的实现看起来就是这样;
我已将GCM和Parse的接收器注册为休耕;
以下接收器适用于GCM;
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.test" />
</intent-filter>
</receiver>
Parse的接收器和服务就像休耕一样;
<service android:name="com.parse.PushService"></service>
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter android:priority="0">
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.test" />
</intent-filter>
</receiver>
我在Application类中将Parse Initialization称为;
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, "APPLICATION_ID", "CLIENT_KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
我已经为GCM实现了GCMIntentService作为休闲;
public class GCMIntentService extends GCMBaseIntentService {
private static final String TAG = "GCMIntentService";
GCMManager gcmManager;
public GCMIntentService() {
super(Config.SENDER_ID);
}
/**
* Method called on device registered
*/
@Override
protected void onRegistered(Context context, String registrationId) {
gcmManager = new GCMManager(context);
Log.i(TAG, "Device registered: regId = " + registrationId);
displayMessage(context, "Your device registred with GCM");
ServerUtilities.register(context, registrationId);
gcmManager.saveGcmRegistrationId(registrationId);
}
/**
* Method called on device un registred
*/
@Override
protected void onUnregistered(Context context, String registrationId) {
Log.i(TAG, "Device unregistered");
displayMessage(context, getString(R.string.gcm_unregistered));
ServerUtilities.unregister(context, registrationId);
}
/**
* Method called on Receiving a new message
*/
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
// displayMessage(context, message);
try {
String message = intent.getExtras().getString(Constant.TAG_MESSAGE);
String id = intent.getExtras().getString(Constant.TAG_ID);
String title = intent.getExtras().getString(Constant.TAG_TITLE);
String type = intent.getExtras().getString(Constant.TAG_NOTIFICATION_TYPE);
Log.e("Message : ", message);
Log.e("Title : ", title);
Log.e("ID : ", id);
Log.e("Type : ", type);
// notifies user
generateNotification(context, message, title, id, type);
} catch (Exception e) {
}
}
}