Skip to content

Instantly share code, notes, and snippets.

@m4scosta
Created August 11, 2016 02:34
Show Gist options
  • Save m4scosta/78e11ece3b6a655d5a439c539652400c to your computer and use it in GitHub Desktop.
Save m4scosta/78e11ece3b6a655d5a439c539652400c to your computer and use it in GitHub Desktop.
Android push notification using Parse Cloud Code
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);
}
});
});
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