【问题标题】:"Pushes sent 0" in parse dashboard for androidandroid 解析仪表板中的“推送发送 0”
【发布时间】:2015-07-15 14:08:36
【问题描述】:

我正在尝试将推送通知从解析发送到 android。从浏览器发送它时,设备的计算正在正确显示。但是浏览器中显示的是“Pushes sent 0”。

我在应用程序类中注册通知

ParsePush.subscribeInBackground("", new SaveCallback() {
    @Override
    public void done(ParseException e) {
        if (e == null) {
            Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
        } else {
            Log.e("com.parse.push", "failed to subscribe for push", e);
        }
    }
});
ParseInstallation.getCurrentInstallation().saveInBackground();

我还在我的 android 项目中创建了Receiver

public class PushMessageBroadcast extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Log.d("The push","open");
    }

    @Override
    protected Notification getNotification(Context context, Intent intent) {
        // TODO Auto-generated method stub
        return super.getNotification(context, intent);
    }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        //here You can handle push before appearing into status e.g if you want to stop it.
        super.onPushReceive(context, intent);
    }
}

我也做了manifest的改动:

<receiver
    android:name=".receivers.PushMessageBroadcast "
    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>

我需要更改解析中的任何设置吗?提前致谢。

【问题讨论】:

  • 尝试将通知发送到所有设备而不是特定频道,看看是否有效
  • 它将始终显示为 0 几分钟。如果在发送推送通知后等待一段时间然后刷新,它应该会更新到正确的设备数量。

标签: java android parse-platform push-notification


【解决方案1】:

修改后的答案

在@lochana-tejas 发表评论后,我意识到我的答案不正确,因为我在 Google 开发者控制台“Android 的云消息传递”中再次禁用,并且我的设备仍然收到了通知。

因此,您需要控制的第一件事是,在 Parse Dashboard 中,您拥有 Installation 类,并且该类注册了一个或多个设备。如果您没有此类或为空“推送已发送”将为 0。

我把我的代码复制在这里,你可以比较

  public static void registerParse(Context context) {
        Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);

        Parse.initialize(context, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
        ParseInstallation.getCurrentInstallation().saveInBackground();

        ParsePush.subscribeInBackground(PARSE_CHANNEL, new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.d("com.parse.push", "Successfully subscribed to Parse!");
                } else {
                    Log.e("com.parse.push", "failed to subscribe for push", e);
                }
            }
        });
    }

    //This is the user that will be inserted in "Installation class"
    public static void subscribeWithUser(String user) {
        ParseInstallation installation = ParseInstallation.getCurrentInstallation();

        installation.put("user", user);

        installation.saveInBackground(new SaveCallback() {
            @Override
            public void done(ParseException e) {
                if (e == null) {
                    Log.e("subscribeWithUser", "User subscribed successfully!!", e);
                } else {
                    e.printStackTrace();
                    Log.e("subscribeWithUser", "Error to save user", e);
                }
            }
        });


    }

我的清单是这样的

        <!-- Added for Parse push notifications -->

        <service android:name="com.parse.PushService" />
        <receiver
            android:name=".receiver.CustomPushReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
                <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>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.parse.starter" />
            </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>   

【讨论】:

  • 你的意思是我们不想添加gcm注册编码但需要在google控制台中创建项目?
  • @LochanaTejas 你是对的。没有必要在 Google Developer 控制台中启用 API,所以我更改了所有答案
  • 是的,现在编辑的答案是正确的。无需在控制台中启用 GCM,也无需在我们的 Android 中添加 GCM 代码。但是我仍然创建了这个项目,并随身携带了我的 senderID,但什么也没做。只需要在清单中进行更改,并将推送注册到用于在收到通知后处理通知的活动
  • 我接受这个答案也包括我上面的评论
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多