MediaStyle:RemoteServiceException:从包中发布的错误通知

2024-03-30

我正在尝试使用下面的代码在我的应用程序中创建一个通知媒体控制器,该代码在所有设备上都可以正常工作华为 P8 Lite with 安卓5.0,我从 Firebase 测试实验室收到此错误日志:

android.app.RemoteServiceException:发布的错误通知 包 maa.app_app:无法扩展 RemoteViews: StatusBarNotification(pkg=maa.app_app 用户=UserHandle{0} id=555 标签=空 分数=10 key=0|maa.app_app|555|null|10108:通知(pri=1 contentView=maa.app_app/0x109007f 振动=null 声音=null 默认=0x0 标志=0x62 颜色=0xffbfbfbf 类别=运输 actions=2 vis=PUBLIC)) 致命异常:主进程: maa.app_app,PID:18793 android.app.RemoteServiceException:发布的错误通知 包 maa.app_app:无法扩展 RemoteViews: StatusBarNotification(pkg=maa.app_app 用户=UserHandle{0} id=555 标签=空 分数=10 key=0|maa.app_app|555|null|10108:通知(pri=1 contentView=maa.app_app/0x109007f 振动=null 声音=null 默认=0x0 标志=0x62 颜色=0xffbfbfbf 类别=运输 行动=2 vis=PUBLIC)) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1534) 在 android.os.Handler.dispatchMessage(Handler.java:102) 处 android.os.Looper.loop(Looper.java:135) 位于 android.app.ActivityThread.main(ActivityThread.java:5538) 在 java.lang.reflect.Method.invoke(本机方法) at java.lang.reflect.Method.invoke(Method.java:372) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

这是我的代码:

void startNotify(Context context, String playbackStatus, String title) {
    String titlesonge;
    String artist;
    try {
        titlesonge = StringUtils.substringBefore(title, " - ");
        artist = StringUtils.substringAfter(title, " - ");
    } catch (Exception e) {
        titlesonge = title.substring(0, title.indexOf(" - "));
        artist = title.substring(title.lastIndexOf(" - ") - 1);
    }
    int icon = R.drawable.ic_pause_white;
    Intent playbackAction = new Intent(service, RadioService.class);
    playbackAction.setAction(RadioService.ACTION_PAUSE);
    PendingIntent action = PendingIntent.getService(service, 1, playbackAction, 0);
    if (playbackStatus.equals(PlaybackStatus.PAUSED)) {
        icon = R.drawable.ic_play_white;
        playbackAction.setAction(RadioService.ACTION_PLAY);
        action = PendingIntent.getService(service, 2, playbackAction, 0);

    }
    Intent stopIntent = new Intent(service, RadioService.class);
    stopIntent.setAction(RadioService.ACTION_STOP);
    PendingIntent stopAction = PendingIntent.getService(service, 3, stopIntent, 0);

    Intent intent = new Intent(service, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP |
            Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(service, 0, intent, 0);
    notificationManager.cancel(NOTIFICATION_ID);
    String PRIMARY_CHANNEL = "PRIMARY_CHANNEL_ID";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager manager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
        String PRIMARY_CHANNEL_NAME = "PRIMARY";
        NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL, PRIMARY_CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        if (manager != null) {
            manager.createNotificationChannel(channel);
        }
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(service, PRIMARY_CHANNEL)
            .setAutoCancel(false)
            .setContentTitle(titlesonge)
            .setContentText(artist)
            .setLargeIcon(BitmapFactory.decodeResource(resources, R.drawable.largeicon))
            .setContentIntent(pendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setSmallIcon(R.drawable.smallwidth)
            .setColor(ContextCompat.getColor(context, R.color.colorneeded))
            .addAction(icon, "pause", action)
            .addAction(R.drawable.ic_stop_white, "stop", stopAction)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setWhen(System.currentTimeMillis())
            .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                    .setMediaSession(service.getMediaSession().getSessionToken())
                    .setShowActionsInCompactView(0, 1)
                    .setShowCancelButton(true)
                    .setCancelButtonIntent(stopAction));
    service.startForeground(NOTIFICATION_ID, builder.build());
}

谁能帮我解决这个问题


由于某些原因,Android 5.0的华为设备在使用时会崩溃.setStyle()方法,所以你有两种可能性:

1 - 检测设备是否为华为制造,是否有Android 5.0或更低版本

public boolean isLolliPopHuawei() {
    return (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 ||
            android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) && Build.MANUFACTURER.equalsIgnoreCase("HUAWEI");
}

2 - Use PlayerNotificationManager反而

void exoPlayerNotification(Context context, SimpleExoPlayer exoPlayer, String title) {
    String titlesonge;
    String artist;
    try {
        titlesonge = StringUtils.substringBefore(title, " - ");
        artist = StringUtils.substringAfter(title, " - ");
    } catch (Exception e) {
        titlesonge = title.substring(0, title.indexOf(" - "));
        artist = title.substring(title.lastIndexOf(" - ") - 1);
    }
    String finalArtist = artist;
    String finalTitlesonge = titlesonge;
    mPlayerNotificationManager = PlayerNotificationManager.createWithNotificationChannel(
            context,
            "PRIMARY_CHANNEL_ID",
            R.string.plaza,
            NOTIFICATION_ID,
            new PlayerNotificationManager.MediaDescriptionAdapter() {
                @Override
                public String getCurrentContentTitle(Player player) {
                    return finalArtist;
                }

                @Nullable
                @Override
                public PendingIntent createCurrentContentIntent(Player player) {
                    Intent intent = new Intent(service, MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    return PendingIntent.getActivity(service, 0, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                }

                @Override
                public String getCurrentContentText(Player player) {
                    return finalTitlesonge;
                }

                @Nullable
                @Override
                public Bitmap getCurrentLargeIcon(Player player, PlayerNotificationManager.BitmapCallback callback) {
                    return BitmapFactory.decodeResource(service.getResources(), R.drawable.largeicon);
                }

                @Nullable
                @Override
                public String getCurrentSubText(Player player) {
                    return null;
                }
            }
    );
    mPlayerNotificationManager.setUseNavigationActions(false);
    mPlayerNotificationManager.setFastForwardIncrementMs(0);
    mPlayerNotificationManager.setRewindIncrementMs(0);
    mPlayerNotificationManager.setColorized(true);
    mPlayerNotificationManager.setColor(0xFFEEEEEE);
    mPlayerNotificationManager.setUseChronometer(true);
    mPlayerNotificationManager.setOngoing(true);
    mPlayerNotificationManager.setPriority(NotificationCompat.PRIORITY_MAX);
    mPlayerNotificationManager.setUsePlayPauseActions(true);
    mPlayerNotificationManager.setSmallIcon(R.drawable.smallwidth);
    mPlayerNotificationManager.setNotificationListener(new PlayerNotificationManager.NotificationListener() {
        @Override
        public void onNotificationStarted(int notificationId, Notification notification) {
            service.startForeground(notificationId, notification);
        }

        @Override
        public void onNotificationCancelled(int notificationId) {
            service.stopSelf();
            cancelNotify();
        }
    });
    mPlayerNotificationManager.setPlayer(exoPlayer);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MediaStyle:RemoteServiceException:从包中发布的错误通知 的相关文章

  • 垂直从上到下线手势检测器

    我用的是 手势工具 注意到对于垂直从上到下的线无法检测 因为我在代码中使用生成的手势文件 如下所示 但无法检测垂直从上到下的线手势检测 import java util ArrayList import android app Activi
  • 从 Android 访问云存储

    我一直无法找到任何有关如何从 Android 应用程序使用云存储的具体文档 我确实遇到过这个客户端库 https cloud google com storage docs reference libraries然而 Google Clou
  • 如何使用共享首选项在两个 Android 应用程序之间共享数据?

    我有两个应用程序 App1 和 App2 我想使用共享首选项在 App1 中保存数据并在 App2 中访问 反之亦然 我可以在 App1 中保存数据并在 App2 中访问数据 但反之则不行 这就是我现在正在做的 在清单中 android s
  • 多线程——更快的方法?

    我有一堂有吸气剂的课程getInt 和一个二传手setInt 在某个领域 比如说领域 Integer Int 一个类的一个对象 比如说SomeClass The setInt 这里是同步的 getInt isn t 我正在更新的值Int来自
  • 如何为 flutter 绘图应用实现橡皮擦功能

    有一个关于通过 flutter 创建绘图应用程序的视频 YouTube https www youtube com watch v yyHhloFMNNA 它支持当用户点击屏幕时绘制线 点 但我找不到像 Android 本机那样擦除用户绘制
  • 分离 Fragment 和删除 Fragment 有什么区别?

    在 Android 文档中碎片交易 http developer android com reference android app FragmentTransaction html我注意到两种非常相似的方法 detach and remo
  • Jetty Plugin 9启动不喜欢icu4j-2.6.1.jar

    我对 mortbay 的 Maven jetty 插件 6 有相同的配置
  • 如何关闭导航抽屉以使用返回主页图标按钮?

    我也将操作栏与搜索栏一起使用 并且我需要像后退按钮一样使用 ActionBar ico 但我也在使用导航抽屉 如何关闭 隐藏 禁用导航抽屉菜单以使用后退按钮 我的 ActionBar 代码 Override public boolean o
  • Android 10 请求 ACTIVITY_RECOGNITION 权限

    我试图遵守 Google 的要求 为 Android 10 请求 ACTIVITY RECOGNITION 权限 但我似乎不明白为什么没有显示权限弹出窗口 就像其他权限 即位置 存储等 一样 我的代码是 if ContextCompat c
  • 推特更新状态

    我正在通过 twitter4j 将 Twitter 集成到 Android 我可以成功阅读我发布的推文 现在我试图用它发布推文 但我不能 我收到如下奇怪的警告 02 01 16 28 43 298 WARN System err 729 4
  • 通知操作而不启动新活动?

    我计划提供一个包含两个操作的提醒通知 一个用于批准登录请求 一个用于拒绝登录请求 通过单击这些操作中的任何一个 我希望向我的服务器发出 HTTP 请求 最重要的是 我不想启动新的 Activity 或根本不想将用户重定向到我的应用程序 Co
  • Android项目中使用java获取电脑的IP地址

    我在用ksoap2 android http code google com p ksoap2 android 我需要使用java获取IP地址 这样我就不必每次都手动输入它 我所说的 IP 地址是指 例如 如果我这样做ipconfig使用命
  • Java 中处理异步响应的设计模式

    我读过类似问答的答案 如何在 JAVA 中创建异步 HTTP 请求 https stackoverflow com questions 3142915 how do you create an asynchronous http reque
  • 如何将库添加到 LIBGDX 项目的依赖项 gradle

    一切都在问题中 我已经尝试了在 SO 和其他网站中找到的所有答案 但没有运气 这就是我迄今为止尝试过的 adding compile fileTree dir lib include jar 到我的 build gradle adding
  • Java 中的微分方程

    我正在尝试用java创建一个简单的SIR流行病模型模拟程序 基本上 SIR 由三个微分方程组定义 S t l t S t I t l t S t g t I t R t g t I t S 易感人群 I 感染人群 R 康复人群 l t c
  • 如何使用注释处理 Hibernate 和 Spring 中的连接查询?

    我正在使用 Spring 和 Hibernate 以及 MySQL 开发应用程序 我是 Hibernate 新手 完成了基本任务 现在我需要在选择查询中应用联接以使用注释从多个表中获取数据 我已经搜索过但仍然没有任何想法 这是我的数据库表和
  • iOS 上的本地通知需要用户许可吗?

    我在我的应用程序中使用 UILocalNotification 来安排通知 通知工作正常 并在我需要时显示 我对此没有意见 我没有做任何远程 推送通知 让我想知道的是 我从未见过您通常在多个应用程序中看到的推送通知的著名权限对话框 我什至重
  • java.lang.ClassCastException:com.sun.proxy.$Proxy8 无法转换为 org.openqa.selenium.internal.WrapsDriver

    我有以下切入点和 AspectJ 中给出的建议 Pointcut call org openqa selenium WebElement sendKeys public void onWebElementAction After onWeb
  • 你能快速告诉我这个伪代码是否有意义吗?

    我相信我的代码现在是万无一失的 我现在将写出伪代码 但我确实有一个问题 为什么 DRJava 要求我返回 if 语句之外的内容 正如你所看到的 我为 ex 写了 return 1 只是因为它问了 但是它永远不会返回该值 谁可以给我解释一下这
  • 使用 AmazonSNSClient 发送短信时的授权

    aws 官方文档如何发送短信 http docs aws amazon com sns latest dg sms publish to phone html使用 java 中的 aws SDK 非常简单 但是 当发送如底部示例所示的消息时

随机推荐

  • Android EditText 错误消息弹出文本未显示

    我的应用程序遇到问题 EditTexts 上显示错误弹出窗口 但文本不可见 它看起来像这样 所有的情况都会发生这种情况EditText在我的应用程序中 这是布局 XML 的示例 Layout
  • 未捕获的引用错误:_gaq 未定义(Google Analytics)

    在 chrome 调试日志中查看站点页面时 会出现以下消息 未捕获的引用错误 gaq 未定义 页面本身应该使用以下方式跟踪对象onload事件处理程序并触发 trackEvent用于谷歌分析 我最好的猜测是也许ga js文件没有及时加载 因
  • 如何在VBA中释放对象并清除内存

    这是我第一次发帖 而且我是一名业余程序员 所以如果您需要任何其他信息 请告诉我 我有以下问题 使用 excel VBA 我连接到另一个程序 即 Aspen EDR 为此 我安装了一个相应的插件 要访问 Aspen EDR 我需要添加一个对象
  • 使用 Castle Windsor 解析具有泛型类型约束的接口

    给定 FooRequest 和 FooResponse 是抽象的接口 public interface IFooHandler
  • Cordova after_prepare hook 在 Android 中成功,但在 iOS 中失败

    我为我的 Cordova 构建编写了一个 after prepare 钩子 它从最终构建中删除了 node modules 文件夹 usr bin env node The node modules we want to remove fr
  • 通知中的 PendingIntent

    我想显示一个显示进度的通知 正在进行的操作 这对我来说效果很好 但同时远程视图应包含取消按钮以停止正在进行的操作 通常的内容意图仍然应该做其他事情 即不取消正在进行的操作 看来我只能有一个意图 我必须指定单击时启动的 contentInte
  • 使用 SVG 和 d3.js 创建滚动条

    现在我已经使用 d3 创建了几个 盒子 它们只是带有文本的 SVG 矩形 var canvas d3 select body append svg attr width 800 attr height 500 specifies drawi
  • 绘制到 UIImage 中

    如何使用 monotouch 绘制现有的 UIImage 我加载图像 UIImage FromFile MyImage png 然后我想在这个图像中绘制一条字符串和一些线条 有人有代码示例吗 Thx 这是一个执行此操作的方法 private
  • 使用 importlib 选择模块并在多处理函数中使用

    我想在我的主函数中根据传递给 Python 脚本的参数选择要导入的模块 所以 我正在使用其中之一 blah importlib import module blah1 blah importlib import module blah2 其
  • C++ 的 putenv 警告

    我正在尝试使用putenv stdlib我正在编译的程序中的函数g 包括标志和警告 std c 11 and Wall Wextra 该程序可以简单如下 include
  • 用于托管服务器的 Web Deploy 3.6 的 PowerShell 安装

    我需要为托管服务器安装 Web Deploy 3 6 通常您会使用 Web 平台安装程序 但我需要使用 PowerShell 来部署它 我找到了 Web Deploy 3 6 的下载 并且可以使用 PowerShell 安装该文件的 MSI
  • 如何在PyQt5中横向打印?

    如何修改此代码以自动打印或将默认设置设置为横向 我是 PyQt5 的新手 尝试制作一个具有打印功能的应用程序 我从互联网上复制并粘贴了此代码 但它的默认设置是纵向 自动横向打印非常重要 from PyQt5 import QtWidgets
  • 错误:没有名为“fcntl”的模块

    我收到以下错误 Traceback most recent call last File C Users aaaa Desktop ttttttt py line 5 in
  • Rockscroll 之类的记事本++ 插件?

    有没有像 Rockscoll for VisualStudio for notepad 这样的插件 至少有接近它的东西吗 Thanks 它是内置的 View gt Document Map
  • Rails link_销毁嵌套资源?

    我有一个嵌套的资源附件 我想创建一个link to销毁 删除附件 这是我所拥有的 但它是作为 GET 与 PUT 发布的 有想法吗 谢谢 Try link to Delete Attachment a
  • 瑞典 BankID 使用 hmac 生成 Python 动画 QR 代码

    我正在开发一个 Django 项目 它将使用 BankID 进行授权和数字签名 我在用pybankid https github com hbldh pybankid 关于这个项目 我除了好话之外没有什么可说的 我的问题在于尝试使用bank
  • 为什么可为 null 的 int 不能隐式转换为 int ?技术原因还是设计选择?

    在 C 中 没有从int 键入int type 我定义了以下隐式运算符 namespace System public partial struct Int32 public static implicit operator Int32 i
  • 关于函数指针转换的澄清

    函数类型 左值 可以转换为函数指针 右值 int func int func ptr func 但从 4 1 1 非函数 非数组类型 T 的左值 3 10 可以转换 到一个右值 这是否意味着函数上未完成左值到右值的转换 另外 当数组衰减为指
  • 如何在 C++ 中编写具有多个数据字段的类似 Java 枚举的类?

    来自 Java 背景的我发现 C 的枚举非常蹩脚 我想知道如何在 C 中编写类似 Java 的枚举 其中枚举值是对象 并且可以具有属性和方法 例如 将以下 Java 代码 其中一部分 足以演示该技术 翻译为 C public enum Pl
  • MediaStyle:RemoteServiceException:从包中发布的错误通知

    我正在尝试使用下面的代码在我的应用程序中创建一个通知媒体控制器 该代码在所有设备上都可以正常工作华为 P8 Lite with 安卓5 0 我从 Firebase 测试实验室收到此错误日志 android app RemoteService