Prithvi
Prithvi

Reputation: 101

I want to send notification to certain android devices on click of a button from android devices using parse

I want to send notification to certain android devices on click of a button from android devices using parse, and i wrote this code snippet, but when i am clicking on button, the push dashboard is showing failure message as shown in screenshotenter image description here:

ParseQuery userQuery = ParseUser.getQuery();
                    /*userQuery.whereWithinMiles("location",
                            currentUser.getParseGeoPoint("Location"), 1.0);*/
                    userQuery.whereNear("location", currentUser.getParseGeoPoint("Location"));
                    userQuery.setLimit(10);
                    userQuery.findInBackground();
                    // Find devices associated with these users
                    ParseQuery pushQuery = ParseInstallation.getQuery();
                    pushQuery.whereMatchesQuery("user", userQuery);

                    // Send push notification to query
                    ParsePush push = new ParsePush();
                    ParsePush.subscribeInBackground("Doctor");
                    push.setQuery(pushQuery);

                    push.setMessage("Only users near"
                            + currentUser.getParseGeoPoint("Location")
                            + " will recieve this push notification");
                    push.sendInBackground();
                }

Upvotes: 0

Views: 129

Answers (1)

Waseem Lateef
Waseem Lateef

Reputation: 151

check userQuery.findInBackground(); call... either try it with synchronous or try to make background (async call) with block..something like this

userQuery.findInBackground(new FindCallback<ParseObject>() 
{
    void done(List<ParseObject> results, ParseException e) {
      if (e != null) {
        // There was an error
      } else {
        // Find devices associated with these users
                    ParseQuery pushQuery = ParseInstallation.getQuery();
                    pushQuery.whereMatchesQuery("user", userQuery);

                    // Send push notification to query
                    ParsePush push = new ParsePush();
                    ParsePush.subscribeInBackground("Doctor");
                    push.setQuery(pushQuery);

                    push.setMessage("Only users near"
                            + currentUser.getParseGeoPoint("Location")
                            + " will recieve this push notification");
                    push.sendInBackground();
      }
    }

for further details see this link https://parse.com/docs/android/guide#queries-queries-on-string-values

Upvotes: 1

Related Questions