Android,播放parcelable数据

 祢好世界末日 发布于 2023-02-06 15:10

我已经实现了一个扩展NotificationListenerService的类,它适用于拾取已发布的通知.

我当时想要接收statusBarNotification对象并广播它.

我会做以下事情:

@Override
public void onNotificationPosted(StatusBarNotification statusBarNotification) {

    Intent intent = new Intent();
    intent.putExtra("STATUS_BAR_NOTIFICATION",statusBarNotification);
    intent.setAction("com.example.NotificationPosted");
    sendBroadcast(intent);
}

但是当我这样做时,我收到以下错误:

01-05 01:50:14.333  19574-19673/com.example W/NotificationListenerService[NotificationListener]? Error running onNotificationPosted
java.lang.RuntimeException: Not allowed to write file descriptors here
        at android.os.Parcel.nativeAppendFrom(Native Method)
        at android.os.Parcel.appendFrom(Parcel.java:431)
        at android.os.Bundle.writeToParcel(Bundle.java:1679)
        at android.os.Parcel.writeBundle(Parcel.java:636)
        at android.app.Notification.writeToParcel(Notification.java:962)
        at android.service.notification.StatusBarNotification.writeToParcel(StatusBarNotification.java:106)
        at android.os.Parcel.writeParcelable(Parcel.java:1285)
        at android.os.Parcel.writeValue(Parcel.java:1204)
        at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
        at android.os.Bundle.writeToParcel(Bundle.java:1692)
        at android.os.Parcel.writeBundle(Parcel.java:636)
        at android.content.Intent.writeToParcel(Intent.java:7013)
        at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2361)
        at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1127)
        at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:365)
        at com.example.NotificationListener.onNotificationPosted(NotificationListener.java:113)
        at android.service.notification.NotificationListenerService$INotificationListenerWrapper.onNotificationPosted(NotificationListenerService.java:168)
        at android.service.notification.INotificationListener$Stub.onTransact(INotificationListener.java:56)
        at android.os.Binder.execTransact(Binder.java:404)
        at dalvik.system.NativeStart.run(Native Method)

任何人都可以看到我做错了什么,或者这是不可能的.StatusBarNotification实现Parcelable

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有