我正在尝试将 StatusBarNotifications 数组发送到我的另一个服务,所以我已经这样做了:
服务延伸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);
}
但我收到有关文件描述符的 RuntimeException 。
我只找到了几个解决此问题的链接,例如这个here https://stackoverflow.com/questions/18706062/android-exception-with-sending-parcelfiledescriptor-via-intent?lq=1。答案提到了以下内容:
使用 Bundle.putBinder() 传递 Binder,它将返回带有 ParcelFileDescriptor 的 Parcel(来自 API 18)。
但我不明白如何实施。
此链接中的另一个人here https://stackoverflow.com/questions/18706062/android-exception-with-sending-parcelfiledescriptor-via-intent#comment27633853_18706062提到以下内容:
如果我从 ContentProvider 返回 PaecelFileDescriptor,它就可以正常工作。
但我不明白他的意思。
最后一个链接是这个here https://stackoverflow.com/questions/20929107/android-broadcasting-parcelable-data。它解决了与我相同的问题,但似乎没有解决方案。
有人理解我链接的这些潜在解决方案吗?此问题是否有解决方法,可能是另一种发送数据的方法(StatusBarNotification[](它扩展了 Parcelable))?
这是日志:
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)
非常感谢这里的一些帮助,因为我无法解决这个问题,而且它开始困扰我,谢谢