安卓GCM注册ID与Parse等第三方库发生冲突

4
我有一个简单的项目,使用我的gcm提供商,同时我想实现解析库来向所有用户发送推送。但是我在这种情况下遇到了问题。当我使用我的GCMSenderID注册gcm时,我获得了registrationID,然后Parse使用其默认的GCMSenderID(1076345567071)注册gcm。然后我意识到,从我的gcm提供商获取的regID已经被写入parse push表作为deviceToken。因此,我认为我无法使用parse向所有设备发送推送消息。 我使用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个回答

5
我通过调用以下命令解决了注册多个发送器的问题:
GoogleCloudMessaging.getInstance(this).register(YOUR_GCMSENDERID,  PARSE_DEFAULT_GCM_SENDERID);

PARSE_DEFAULT_GCM_SENDERID = 1076345567071


非常感谢您的回答,Parse默认的senderID真的很重要。谢谢,伙计! - moujib

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接