getting straight to the point, I can send push notifications from my app to other apps which have the same Channel name as it. Now my requirement is that I need to send to a particular user. Read some documentation about it but was still unclear of how to achieve that. This is what I've done so far.
Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyy");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("words");
On Button Click:
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereEqualTo("user", receiver);
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setChannel("words");
push.setMessage(ParseUser.getCurrentUser().getUsername() + " sent you a Gift");
push.sendInBackground();
删除push.setQuery(pushQuery);
My solution is good for you only if:
you associating every installation with user: ParseInstallation.currentInstallation.put("user",ParseUser.currentUser)
//search all receiver users
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("user", receiver);
userQuery.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> users, ParseException e) {
if (users != null && users.size() > 0) {
//now you have all receivers
for (int i = 0; i < users.size(); i++) {
ParseUser user = users.get(i);
//now searching needed channel inside array of receivers
ArrayList<JSONObject> channels = (ArrayList<JSONObject>) user.get("channels");
if (channels.contains("words")){
//here sending the push
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
ParseQuery<ParseInstallation> installationQuery = ParseInstallation.getQuery();
userQuery.whereEqualTo("user", user);
installationQuery.whereMatchesQuery("user", userQuery);
ParsePush push = new ParsePush();
push.setQuery(installationQuery);
push.setMessage(ParseUser.getCurrentUser().getUsername() + " sent you a Gift");
push.sendInBackground();
}
}
}
}
});
If your user using the same account in many devices with different channels so this is not solution for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.