Sending object as Parcel (with file descriptors) t

2019-03-29 00:06发布

I am trying to send an array of StatusBarNotifications to another service of mine so I have done 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 concerning file descriptors.

I have only found a few links addressing this issue for example this one here. The answer mentions the following:

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

Another guy in this link here mentions the following:

If I return PaecelFileDescriptor from a ContentProvider, it works just fine.

But I do not understand what he means by that.

A last link is this one here. It addresses the same issue as I am but there seems to be no solution.

Does anyone understand these potential solutions I linked? Is there a workaround for this issue, potentially another way to send the 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)

Would really appreciate some help here as I haven't been able to solve this problem and it's starting to do my head in, thanks

0条回答
登录 后发表回答