android Gcm registrationID与Parse等第三方库发生冲突

时间:2015-05-07 11:05:50

标签: android parsing

我有一个使用我的gcm提供程序的简单项目,我也希望实现解析库来为所有用户发送推送。但我对这种情况有一个问题。当我使用GCMSenderID注册gcm时,我获得registrationID,然后Parse使用其默认的GCMSenderID(1076345567071)注册gcm。然后我意识到从我的gcm提供程序获取的regID已将解析推送表写为deviceToken。出于这个原因,我认为,我无法通过解析向所有设备发送推送消息。 我使用parse quickstart实现也从parse.com/docs/push_guide#top/Android进行一些研究。 我该如何解决这个冲突?

这是我的实施:

的AndroidManifest.xml         

    <service android:name="com.parse.PushService" />

    <meta-data
        android:name="com.parse.push.notification_icon"
        android:resource="@drawable/icon" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <receiver
        android:name=".gcm.GcmBroadcastReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="xxx.android" />
        </intent-filter>
    </receiver>


    <receiver android:name="com.parse.ParseBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver
        android:name="com.parse.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="xxxx.android" />
        </intent-filter>
    </receiver>
    <receiver
        android:name=".gcm.ParseReceiver"
        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>

Application.java

    Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    Parse.initialize(this, ParseAPPLICATION_ID, ParseCLIENT_KEY);                    
    ParseInstallation.getCurrentInstallation().saveInBackground();

Parse使用其默认发件人ID来请求GCM注册令牌:特别是,SDK会在启动时使用Parse的发件人ID(1076345567071)自动注册您的应用程序,并将生成的注册ID存储在应用程序当前ParseInstallation的deviceToken字段。 (来自parse.com/docs/push_guide#top/Android)。因此,在启动时请求注册GCM令牌,我的问题是:我怎样才能确定哪个regToken Parse收到哪个regToken我的GCM实现/客户端收到了什么?从理论上讲,他们可能会混在一起?

1 个答案:

答案 0 :(得分:5)

我通过调用:

来修复此问题并注册了多个发件人
GoogleCloudMessaging.getInstance(this).register(YOUR_GCMSENDERID,  PARSE_DEFAULT_GCM_SENDERID);

PARSE_DEFAULT_GCM_SENDERID = 1076345567071