通过 Intent 将对象作为 Parcel(带有文件描述符)发送会导致异常

2023-12-19

我正在尝试将 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)

非常感谢这里的一些帮助,因为我无法解决这个问题,而且它开始困扰我,谢谢


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 Intent 将对象作为 Parcel(带有文件描述符)发送会导致异常 的相关文章

随机推荐

  • 如何将新的和更新的行从离线数据库复制到在线数据库?

    这是一种情况 您有一个桌面应用程序 并且其数据库位于远程服务器中 就我而言 它是 MySQL 应用程序是用 Delphi XE3 编写的 但是 当客户想要离线和在线数据时 为了速度和安全 我们需要 使用远程服务器信息登录 更多更新 将线上数
  • 发生异常时整个 blazor Web 应用程序停止工作

    请为我提供以下问题的任何合适的解决方案 当 blazor 应用程序抛出任何异常时 整个应用程序就会崩溃并且没有链接起作用 直到我可以再次通过工作室运行该应用程序 对于这个问题该怎么办 谢谢并致以诚挚的问候 Edited 为了提供所需的信息
  • recaptcha 没有通过 selenium python 中的 anticaptcha 插件解决

    我最近开始在一个涉及自动化的项目中使用 selenium 该计划中的障碍之一是 ReCaptcha 系统 因此我决定使用反验证码作为当我的机器人遇到验证码时解决验证码的服务 我正确安装了该插件 并在他们的网站上找到了一些带有硒的测试代码 f
  • 什么是声明式编程? [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 Locked 这个问题及其答案是locked help locked posts因为这个问题是题外话 但却具有历史意义 目前不接受新的
  • 将行添加到具有动态列的 HTML 表中

    我正在使用下面的代码 作为上一个问题的解决方案提供将 mySQL 记录显示为 HTML 表列 https stackoverflow com questions 21870246 display mysql records as html
  • 如何判断 Windows 上的 Python 进程是否响应

    我正在编写一个 python 脚本来保持有错误的程序打开 我需要弄清楚该程序是否没有响应并在 Windows 上将其关闭 我不太清楚该怎么做 在 Windows 上您可以执行以下操作 import os def isresponding n
  • ggplot 中月份缩放时条形宽度不一致

    查了好久 没找到讨论类似问题的帖子 我在日期缩放方面遇到问题ggplot 我认为这与方式有关ggplot正在处理日期 我试图消除列之间的所有空白 因为我的最终结果将类似于以下内容 这是一个显示跨月项目的容量规划图表 即使使用默认的缩放和宽度
  • 用 rgl 填充球体上的区域

    这是世界各国首都的球形 Vorono 镶嵌 我有定义每个国家边界的点的坐标 我想用颜色填充这些国家 动机是用与海洋相同的颜色绘制沃罗诺伊边缘 这样我们就不会在国外看到它们 换句话说 我正在寻找类似于polygon函数 但适用于球面多边形 E
  • JSON、Jackson 和多行字符串

    我有以下 JSON content value 我让 Jackson 构建 JSON 字符串 如果该值是多行文本 例如 A B C 我看到的是 content A r nB r nC 它明确规定 r n CRLF 每行 我想知道我是否可以配
  • 单击时使用 jQuery 获取输入值[重复]

    这个问题在这里已经有答案了 我有以下内容 checkbox click function console log this ajax type POST url loadProducts data success function resp
  • iPhone SDK - 带 + 联系人按钮的 UITextField

    在某些应用程序 例如邮件 中 当您有 UITextField 时 右侧会有一个小 按钮 当您点击它时 会出现一个模式视图控制器 您可以从中选择电话号码 地址等 它将出现在文本字段中 我想知道如何在我自己的应用程序中实现这一点 谢谢 Isaa
  • Android:: 使用其他 InputFilter 以编程方式设置 EditText 的最大长度

    我像这样使用 InputFilter 只允许字母和数字 private InputFilter inputFilters new InputFilter new InputFilter Override public CharSequenc
  • 零是有效的句柄吗?

    有一个SafeHandleZeroOrMinusOneIsInvalid NET Framework 中的类 以及SafeHandleMinusOneIsInvalid class 为什么是这样 在哪些情况下零是有效句柄 作为其他答案的补充
  • 桌面 MEF 中的 ExportFactory 去了哪里?

    我找不到它 ExportFactory
  • 无法使用 SQL Native Client 从经典 ASP 连接到 SQL Server 2008 R2 (Windows 7 - IIS7)

    当我使用时 我能够连接到 SQL Server 2008 R2Provider SQLOLEDB在我的连接字符串中 但是当我使用Provider SQLNCLI在连接字符串中我无法连接 ADODB 连接错误 800a0e7a 找不到提供者
  • Qt 中同一标题栏中的最小化按钮和上下文帮助按钮

    要在 QWidget 类型的 Qt 窗口的标题栏中制作帮助按钮 我喜欢这样 myWindow gt setWindowFlags Qt WindowContextHelpButtonHint 这很好用 要在同类窗口的标题栏中制作最小化按钮
  • 如何追踪修订历史记录?

    我正在开发一个编程教程项目 我希望本教程的示例源代码具有有意义的修订历史记录 与教程的进度相关 不可避免的是 我不会在第一次就完全正确地获得所有教程提交 并且我不希望修订历史记录中充斥着我以元方式修改教程提交的提交 我认为这意味着我需要两个
  • Django 发送 POST 请求时返回 403 错误

    当我使用以下 Python 代码向我的 Django 网站发送 POST 请求时 出现 403 Forbidden 错误 url http www sub example com values var test try data urlli
  • 停止 NSView 打印

    我在 Xcode 中有一个非常基本的 Mac 应用程序 带有一个分割视图 其中包含一个 PDFThumbnailView 和一个 PDFView 就像预览一样 除了将 PDF 加载到视图所需的代码之外 几乎没有任何 Swift 代码 但是
  • 通过 Intent 将对象作为 Parcel(带有文件描述符)发送会导致异常

    我正在尝试将 StatusBarNotifications 数组发送到我的另一个服务 所以我已经这样做了 服务延伸NotificationListenerService Override public void onNotification