Sending an object as a parcel (with file descriptors) using exception exceptions

I am trying to send an array of StatusBarNotifications to another service, so I did this:

Service that extends NotificationListenerService :

 @Override public void onNotificationPosted(StatusBarNotification sbn) { // TODO Auto-generated method stub StatusBarNotification[] activeN = super.getActiveNotifications(); Intent i = new Intent(this, CoreTwo.class); i.putExtra("activenotifications", activeN); startService(i); } 

But I get a RuntimeException regarding file descriptors.

I found some links to this problem, for example, here . The answer mentions the following:

use Bundle.putBinder () to pass a Binder that will return Parcel with ParcelFileDescriptor (from API 18). But I do not understand how to implement this.

Another guy in this link here mentions the following:

If I return the PaecelFileDescriptor from the ContentProvider, it works fine.

But I do not understand what he means.

The last link is here . It solves the same problem as me, but there seems to be no solution.

Does anyone understand these potential solutions that I have linked? Is there a workaround for this problem, a potentially different way to send data (StatusBarNotification [] (it extends Parcelable))?

Here is the log:

  08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): Error running onNotificationPosted 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): java.lang.RuntimeException: Not allowed to write file descriptors here 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.nativeAppendFrom(Native Method) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.appendFrom(Parcel.java:431) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Bundle.writeToParcel(Bundle.java:1679) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeBundle(Parcel.java:636) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.app.Notification.writeToParcel(Notification.java:962) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.service.notification.StatusBarNotification.writeToParcel(StatusBarNotification.java:106) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeParcelable(Parcel.java:1285) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeParcelableArray(Parcel.java:1984) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeValue(Parcel.java:1248) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeArrayMapInternal(Parcel.java:618) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Bundle.writeToParcel(Bundle.java:1692) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Parcel.writeBundle(Parcel.java:636) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.content.Intent.writeToParcel(Intent.java:7013) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.app.ActivityManagerProxy.startService(ActivityManagerNative.java:2975) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1506) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.app.ContextImpl.startService(ContextImpl.java:1488) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.content.ContextWrapper.startService(ContextWrapper.java:494) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at com.project.now.NoLiSe.onNotificationPosted(NoLiSe.java:18) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.service.notification.NotificationListenerService$INotificationListenerWrapper.onNotificationPosted(NotificationListenerService.java:168) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.service.notification.INotificationListener$Stub.onTransact(INotificationListener.java:56) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at android.os.Binder.execTransact(Binder.java:404) 08-23 16:49:36.839: W/NotificationListenerService[NoLiSe](12804): at dalvik.system.NativeStart.run(Native Method) 

I would like some help here, since I could not solve this problem, and it starts to do its job, thanks

+6
source share

Source: https://habr.com/ru/post/974249/


All Articles