title: Android Parse.com push notification not sent
body: <h1>Background</h1>
  
  <p>I have an Android app with a <strong>working receiver</strong> that can receive the push notification sent from iOS device and Parse website.</p>
  
  <p>However, the following cases are not working:</p>
  
  <ul>
  <li>send push notifications from Android to Android</li>
  <li>send push notifications from Android to iOS</li>
  </ul>
  
  <p>Since the Android app can receive push notifications without any problems, I guess there must be something with my logic/code of sending the push notifications</p>
  
  <h1>Problem Description</h1>
  
  <p>When sending push notifications using <code>parsePush.sendInBackground(SendCallback)</code> method, it returns no <code>ParseException</code>s. So it means no error.</p>
  
  <p>But the Parse Dashboard does not show this push notifications and the target destination (either iOS or Android device in this case) does not get anything.</p>
  
  <p>In the normal case, when a push notification is sent via Parse, it will show up as a push history in the Dashboard (the working case does that), but when I tried to send pushes from Android device, it just not show anything in the Dashboard and the pushes are never get delivered.</p>
  
  <h1>Code</h1>
  
  <p>The problematic Android code:</p>
  
  <pre><code>public void onShouldSendPushData(MessageClient messageClient, Message message, List&lt;PushPair&gt; pushPairs) {
          //TODO setup offline push notification
          Log.d(TAG, "Recipient not online. Should notify recipient using push");
          if (pushPairs.size() &gt; 0 &amp;&amp; !chatRecipient.isEmpty()) {
              PushPair pp = pushPairs.get(0);
              String pushPayload = pp.getPushPayload();
  
              ParsePush parsePush = new ParsePush();
              ParseQuery query = ParseInstallation.getQuery();
              ParseQuery userQuery = ParseUser.getQuery();
              userQuery.whereEqualTo("username", chatRecipient);
              query.whereMatchesQuery("user", userQuery);
              parsePush.setQuery(query);
  
              // JSON object for android push
              String alertString = getResources().getString(R.string.push_notification_msg);
  
              try {
                  JSONObject data = new JSONObject();
                  data.put("alert", String.format(alertString, chatRecipient));
                  data.put("badge", "Increment");
                  data.put("sound", "default");
                  // pass the sender name as "title"
                  data.put("title", ParseUser.getCurrentUser().getUsername());
                  data.put("uri", "");
                  data.put("SIN", pushPayload);
  
                  parsePush.setData(data);
                  parsePush.sendInBackground(new SendCallback() {
                      @Override
                      public void done(ParseException e) {
                          if (e == null) {
                              Log.i(TAG, String.format("Push notification to %s sent successfully", chatRecipient));
                          } else {
                              Log.e(TAG, String.format("Private chat push notification sending error: %s", e.getMessage()));
                          }
                      }
                  });
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>The working iOS code:</p>
  
  <pre><code>- (void)message:(id&lt;SINMessage&gt;)message shouldSendPushNotifications:(NSArray *)pushPairs {
      // use parse to send notifications
      // send notifications
      NSLog(@"Recipient not online. Should notify recipient using push");
      if (pushPairs.count &gt; 0 &amp;&amp; userSelected != nil) {
          pushData = [[pushPairs objectAtIndex:0] pushData];
          pushPayload = [[pushPairs objectAtIndex:0] pushPayload];
  
          PFPush *push = [[PFPush alloc] init];
          PFQuery *query = [PFInstallation query];
          PFQuery *userQuery = [PFUser query];
          [userQuery whereKey:@"username" equalTo:userSelected];
  
          [query whereKey:@"user" matchesQuery:userQuery];
          [push setQuery:query];
          NSDictionary *data = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSString stringWithFormat:@"You have a new Message from %@", [PFUser currentUser].username], @"alert",
                                @"Increment", @"badge",
                                @"default", @"sound",
                                pushPayload, @"SIN",
                                nil];
  
          [push setData:data];
          [push sendPushInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
              if (succeeded) {
                  NSLog(@"Push notification to %@ sent successfully.", userSelected);
              } else {
                  NSLog(@"push notifications sending error: %@", error);
              }
          }];
      } else {
          NSLog(@"Error: No push pairs.");
      }
  </code></pre>
  
  <h1>Note</h1>
  
  <p>I can confirm that the code above is getting called each time I want to send push notifications, and no exceptions are returned. I can also confirm that the data packaged inside the push is not null.</p>
  
  <p>I'm not posting the receiver's code as that part of code is working and should do nothing with this issue.</p>
  
  <p>The iOS code and Android code basically are the same, why the sending pushes function in Android not working?</p>
  
  <h1>UPDATE</h1>
  
  <p>I upgraded Parse SDK to 1.8.2, with its Logging options set to VERBOSE and still can't find any clue why the Push notifications are not sent.</p>
  
  <p>I even made a simple project out of the Parse example project with only Login and send message functions and its sending message function is still not working. So frustrating.</p>