Your code is working, but you need to make "SignUp" and "Login" on each device and put location to each loggined user
I do it like that but it is not properly, but working:
add it to your MyApplication.class extands Application :
Parse.enableLocalDatastore(this);
Parse.initialize(this, "TWRSFDFayfTlDsiiELyX37crtgezMs0DeQ5IXTdx", "ukuYgUJhhVybV4MtmlkKqtbkj2drEWjl5RJgpqYl");
ParseInstallation.getCurrentInstallation().saveInBackground();
// Also in this method, specify a default Activity to handle push notifications
PushService.setDefaultPushCallback(this, MainActivity.class);
String android_id = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
Log.e("LOG","android id >>" + android_id);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("UniqueId",android_id);
installation.saveInBackground();
String installationID = installation.getInstallationId();
ParseUser.logInInBackground(installationID, installationID, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.e(tag, "Logigned 1");
addCurrentLocation();
} else {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
String installationID = installation.getInstallationId();
user = new ParseUser();
user.setUsername(installationID);
user.setPassword(installationID);
user.setEmail(installationID+"@example.com");
// other fields can be set just like with ParseObject
// user.put("phone", "650-253-0000");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Log.e(tag, "signUp 1");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
String installationID = installation.getInstallationId();
ParseUser.logInInBackground(installationID, installationID, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.e(tag, "Logigned 2");
addCurrentLocation();
} else {
Log.e(tag, "CANT LOGIN");
}
}
});
} else {
Log.e(tag, "signUp error 2");
}
}
});
}
}
});
after first run of app each device will be logigned with username= installationID and password = installationID you will see it on Core->Data->User Doasboard on website
after logining you need to set to each user his location simply method addCurrentLocation();
void addCurrentLocation(){
ParseGeoPoint point = new ParseGeoPoint(12, 12);
ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();;
parseInstallation.put("user",
ParseUser.getCurrentUser());
ParseUser u= ParseUser.getCurrentUser() ;
u.put("location", point);
u.put("application", getString(R.string.app_name));
ParseGeoPoint userlocation = u.getParseGeoPoint("location");
Log.e(tag ,
"user current location: "
+userlocation.getLatitude()
+" : "+
userlocation.getLongitude());
u.saveInBackground();
}
and then post your push notification :
// Find users near a given location
ParseQuery userQuery = ParseUser.getQuery();
ParseGeoPoint stadiumLocation = new ParseGeoPoint(12.1,12.1);
userQuery.whereWithinMiles("location", stadiumLocation , 1.0);
// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Only users near 12,12 will recieve this push notification");
push.sendInBackground();