相关疑难解决方法(0)

Android Parse Push通知设备只在一台设备上注册一次

每个人都在我的应用程序中使用解析服务进行推送通知.但是当我在一台设备上重新安装应用程序时,它会一直注册.然后问题是,一台设备会在每台设备上收到多个通知.我已经完成了一些注册代码,如下所示.请帮助我,提前谢谢.

Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
ParseACL defaultACL = new ParseACL();
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().getInstallationId();
ParseInstallation.getCurrentInstallation().saveInBackground();
Run Code Online (Sandbox Code Playgroud)

并订阅:

PushService.subscribe(this, userName, Detail.class);
Run Code Online (Sandbox Code Playgroud)

在清单中

以上

  <permission
    android:name="com.example.app.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

  <uses-permission android:name="com.example.app.permission.C2D_MESSAGE" />
Run Code Online (Sandbox Code Playgroud)

在应用标签中:

    <receiver android:name="com.parse.ParseBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="act" />
        </intent-filter>
    </receiver>

    <receiver android:name="com.app.example.PushReceiver" >

        <intent-filter>
            <action android:name="act" />
            </action>
        </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" />
            <action android:name="act" />
            <category android:name="com.example.app" />
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

每次我安装时,都显示错误,如下所示.

03-10 12:18:48.555: E/ParseCommandCache(12709): Failed to …
Run Code Online (Sandbox Code Playgroud)

android push-notification devicetoken parse-platform google-cloud-messaging

15
推荐指数
3
解决办法
2万
查看次数

"必须在此操作中指定至少一个ID字段(installationId,deviceToken)"parse

这很简单,当你第一次在手机上使用解析时,它就像一个魅力.当您重新安装应用程序时,它会拧紧所有内容.

作为上注明计算器伊兰:

"PushService.subscribe似乎将订阅缓存在本地存储中,以避免在多次启动应用程序时重新订阅.这是该方法的第一个参数用于:context - 用于访问本地存储以进行缓存订阅,所以它目前必须是一个可行的上下文.(引自这里).

但是,卸载应用程序时,将从您的设备中删除该应用程序的本地存储,因此新安装将导致PushService.subscribe重新注册到Google Cloud Messaging.如果新注册返回新的注册ID,则Parse将具有两个注册ID,可用于向您的应用发送推送通知,并且它们都将链接到您提供给订阅的相同userName.因此,向该userName发送通知会将其发送到两个注册ID,导致它到达两次.

当Parse为您发送通知时,他们应该通过canonical_registration_id从Google获取回复,这会让他们知道您设备上与您的应用相关联的注册ID之一已过时,不应再使用了.因此(假设Parse有一个不错的GCM实现),下次你向设备发送通知时,你应该只收到一次."

这是我的安装源代码:

String  androidId = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
Parse.initialize(this, "KEY1", "KEY2");
PushService.setDefaultPushCallback(this, ParseActivity.class);

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("UniqueId",androidId);

installation.setObjectId(null);

installation.saveInBackground();
Run Code Online (Sandbox Code Playgroud)

我的堆栈跟踪(像每个人一样):

05-20 19:47:35.630: E/ParseCommandCache(6497): com.parse.ParseException: at least one ID field (installationId,deviceToken) must be specified in this operation
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseCommand.onPostExecute(ParseCommand.java:334)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:321)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.ParseRequest$5.then(ParseRequest.java:318)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$11.run(Task.java:481)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task$ImmediateExecutor.execute(Task.java:673)
05-20 19:47:35.630: E/ParseCommandCache(6497):  at com.parse.Task.completeAfterTask(Task.java:477)
05-20 …
Run Code Online (Sandbox Code Playgroud)

android parse-platform

7
推荐指数
1
解决办法
3386
查看次数