user3622184
user3622184

Reputation: 13

Send Parse Push notification with specific user

I'm programming an Android App about share different content. Now I develop the social network, and when one user add new friend, send a Parse Push notification that the user add you.

I use Parse SDK, and I don't now how to do this.

I try this:

ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("userId",id);
try {
    installation.save();

This create a userId column in Installation class of Parse Data. (I see Parse Data and the userId column is the correct id from user)

Next I do:

   //Create our Installation query
   ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery();
   pushQuery.whereEqualTo("userId",ParseUser.getCurrentUser().getObjectId());

   // Send push notification to query
   ParsePush push = new ParsePush();
   push.setQuery(pushQuery); // Set our Installation query
   push.setMessage("Willie Hayes injured by own pop fly.");
   push.sendInBackground();

I create a query that compare the userId colum (that contains the userId from user that add you) with the current ParseUser, but the Push don't send, and nobody receive.

Please help me.

Thanks.

Upvotes: 1

Views: 1330

Answers (1)

Dehli
Dehli

Reputation: 5960

What I did is I registered the device to a channel corresponding with the user. In Swift I did it like this, but in Android it would be very similar. This means that user "userId" would be subscribed to channel "user_userId".

let currentInstallation = PFInstallation.currentInstallation()
currentInstallation.channels = ["user_" + PFUser.currentUser().objectId]
currentInstallation.saveInBackground()

Then when you want to send the push, send it to channel "user_userId".

Upvotes: 1

Related Questions