【发布时间】:2016-08-29 18:51:38
【问题描述】:
在从 Parse 迁移到 Back4App 之前,我可以通过查询我想要发送推送通知的用户的 Installation 对象来轻松发送这样的推送通知:
private void handleLikeNotification(ParseObject messageObject) {
String userId = messageObject.getParseObject(ParseConstants.KEY_SENDER_AUTHOR_POINTER).getObjectId();
String result = messageObject.getString(ParseConstants.KEY_NOTIFICATION_TEXT);
// Initiate installation query
ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
pushQuery.whereEqualTo("userId", userId);
// Create push notification
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Liked by " + ParseUser.getCurrentUser().getUsername() + ": " + result);
push.sendInBackground();
// Check condition and send push notification
if (!userId.equals(ParseUser.getCurrentUser().getObjectId())) {
send(notification);
}
protected void send(ParseObject notification) {
notification.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
// success!
} else {
// notification failed to send!
}
}
});
}
我遵循了他们的文档,并且我的 Receiver 工作正常,因为我可以通过他们的仪表板向我自己和我的用户发送通知。
我对 StackOverflow 的问题是为什么我不能通过我的应用创建和发送这样的推送通知?这个相同的代码适用于我的应用程序,它仍然由原始 Parse 托管解决方案托管。
我的推送通知现在由 GCM 提供,所以我想我需要使用 GCM 类发送它们,但我不知道在哪里查看。
此时我最好的假设是ParsePush 类不适用于我当前的配置。有什么选择?
【问题讨论】:
标签: java android parse-platform push-notification google-cloud-messaging