title: Android capture and send notifications through bluetooth
body: <p>I have two android devices. I have developed two codebases. One is the sender codebase and the other the receiver. Both these are connected via Bluetooth Socket connection and I am able to send simple Strings between them.</p>
  <p>On the sender device I have implemented a <a href="https://developer.android.com/reference/android/service/notification/NotificationListenerService" rel="nofollow noreferrer">NotificationListenerService</a> which captures notifications from that device. I am getting an object of type <a href="https://developer.android.com/reference/android/service/notification/StatusBarNotification" rel="nofollow noreferrer">StatusBarNotification</a> for each notification. As per the documentation, this object implements the Parcelable interface.</p>
  <p>In order to transmit this object, I have tried using GSON, as well as using Parcel object to marshall and send the data. This was not working, so I stopped worrying about the sending part, and tried to see on the same device whether this would marshall and unmarshall correctly.</p>
  <p>Here is the Kotlin code for both,</p>
  <pre><code>/*
   * Using Gson for serialization.
   * 
   * Parts of the object e.g. deserializedObject.notification are missing
   */
  val serializedString = Gson().toJson(sbn)
  val deserializedObject = Gson().fromJson&lt;StatusBarNotification&gt;(serializedString, StatusBarNotification::class.java)
  
  </code></pre>
  <pre><code>/*
   * Using Parcel for serialization.
   *
   * Throws this error,
   * Caused by: java.lang.RuntimeException: Tried to marshall a Parcel that contained Binder objects.
   */
  val parcel = Parcel.obtain()
  parcel.writeValue(sbn)
  val bytes = parcel.marshall()
  
  val p2 = Parcel.obtain()
  p2.unmarshall(bytes, 0, bytes.size)
  val result = p2.readValue(StatusBarNotification::class.java.classLoader) as StatusBarNotification
  </code></pre>
  <p>Any direction would be appreciated.</p>
  <p><strong>Update 1</strong></p>
  <p>I have tried creating a custom data class object. Serialization and deserialization for that works perfectly fine over bluetooth, and I am getting the data on the 2nd device. However I have narrowed it down and my problem remains that the StatusBarNotification object does not play well with serialization.</p>
  <p><code>val serializedCode = Gson().toJson(statusBarNotification)</code>
  in debugger gives
  <code>{&quot;id&quot;:1815187780,&quot;pkg&quot;:&quot;org.telegram.messenger&quot;,&quot;uid&quot;:10260}</code></p>
  <p>Any leads would be appreciated.</p>
  <p><strong>Update 2</strong></p>
  <p>If there is any official way to implement notification reply through Android, a guidance on that would be appreciated as well.</p>