title: OSNotificationPayload cannot be converted to JSONObject
body: <p><strong>THE SITUATION:</strong></p>
  
  <p>In my <a href="https://quasar-framework.org/" rel="nofollow noreferrer">Quasar</a> hybrid app I need to implement some native functionality to receive <a href="https://documentation.onesignal.com/docs/silent-notifications" rel="nofollow noreferrer">background notifications</a>.</p>
  
  <p>I send Push notification using <a href="https://onesignal.com/" rel="nofollow noreferrer">OneSignal</a>, from my API.</p>
  
  <p>In the payload I add a <code>notification_type</code> that will tell if the notification is silent or not (has to be displayed in the phone or not).</p>
  
  <p>When I receive the notification, I need to read that payload, but I don't manage.</p>
  
  <p><strong>THE CODE:</strong></p>
  
  <p>This is the NotificationService:</p>
  
  <pre><code>package com.myapp.app;
  
  import android.util.Log;
  import org.json.JSONObject;
  
  import com.onesignal.OSNotificationPayload;
  import com.onesignal.NotificationExtenderService;
  import com.onesignal.OSNotificationReceivedResult;
  
  public class NotificationService extends NotificationExtenderService {
     @Override
     protected boolean onNotificationProcessing(OSNotificationReceivedResult receivedResult) {
  
       if (receivedResult != null) {
  
          JSONObject data = receivedResult.payload;
          // check data - if notification_type is 'silent' than return true otherwise return false
          return false;
       }
     }
  }
  </code></pre>
  
  <p><strong>THE ERROR:</strong></p>
  
  <pre><code>error: incompatible types: OSNotificationPayload cannot be converted to JSONObject
          JSONObject data = receivedResult.payload;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dfJfr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dfJfr.png" alt="enter image description here"></a></p>
  
  <p><strong>REFERENCES:</strong></p>
  
  <p>Here is some example from the OneSignal Android SDK repo:</p>
  
  <p><a href="https://github.com/OneSignal/OneSignal-Android-SDK/blob/master/Examples/AndroidStudio/app/src/main/java/com/onesignal/example/NotificationExtenderExample.java" rel="nofollow noreferrer">https://github.com/OneSignal/OneSignal-Android-SDK/blob/master/Examples/AndroidStudio/app/src/main/java/com/onesignal/example/NotificationExtenderExample.java</a></p>
  
  <p>It concern background notifications, but in this case they don't read the content of <code>receivedResult</code>.</p>
  
  <p>Here is nice example I am following:</p>
  
  <p><a href="https://www.programcreek.com/java-api-examples/?code=AppHero2/Raffler-Android/Raffler-Android-master/app/src/main/java/com/raffler/app/service/NotificationService.java#" rel="nofollow noreferrer">https://www.programcreek.com/java-api-examples/?code=AppHero2/Raffler-Android/Raffler-Android-master/app/src/main/java/com/raffler/app/service/NotificationService.java#</a></p>
  
  <p>In this case it reads the data like this:
  <code>JSONObject additionalData = receivedResult.payload.additionalData;</code></p>
  
  <p><strong>THE API:</strong></p>
  
  <p>This is how I send push notifications from my Laravel API</p>
  
  <pre><code>private function send_notification_curl($order) {
      $content      = array(
          "en" =&gt; "notification message...",
      );
      $fields = array(
          'data' =&gt; array(
              'order_id' =&gt; $order-&gt;id,
              'notification_type' =&gt; 'silent'
          ),
          'contents' =&gt; $content,
          // some other params...
      );
  
      $fields = json_encode($fields);
  
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
          'Content-Type: application/json; charset=utf-8',
          'Authorization: Basic my_key'
      ));
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      curl_setopt($ch, CURLOPT_HEADER, FALSE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  
      $response = curl_exec($ch);
      curl_close($ch);
  
      return $response;
  }
  </code></pre>
  
  <p><strong>THE QUESTION:</strong></p>
  
  <p>How can I read the content of <code>receivedResult</code>?</p>
  
  <p>Can I convert it to a json object?</p>
  
  <p>Do you know why am I getting that error?</p>