Created
August 11, 2016 02:34
-
-
Save m4scosta/78e11ece3b6a655d5a439c539652400c to your computer and use it in GitHub Desktop.
Android push notification using Parse Cloud Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parse.Cloud.define("push", function (request, response) { | |
var query = new Parse.Query(Parse.Installation); | |
query.equalTo("installationId", request.params.installationId); | |
Parse.Push.send({ | |
where: query, | |
data: request.params.data | |
}, { | |
useMasterKey: true, | |
success: function () { | |
response.success("Success!"); | |
}, | |
error: function (error) { | |
response.error("Error! " + error.message); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String installationId = "INSTALLATION_ID"; // replace with correct installationId | |
Map<String, String> data = new HashMap<String, String>(); | |
data.put("alert", "Hello there!"); // replace with correct message | |
Map<String, Object> params = new HashMap<String, Object>(); | |
params.put("installationId", installationId); | |
params.put("data", data); | |
ParseCloud.callFunctionInBackground("push", params, new FunctionCallback<Object>() { | |
@Override | |
public void done(Object response, ParseException e) { | |
if (e == null) { | |
// push was sent | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment