java - android 通知 - RemoteServiceException

标签 java android android-notifications

我收到 RemoteServiceException。如果我只是在 Activity 的 onResume() 中调用以下内容,就会发生这种情况:

 NotificationManager mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder notif = new NotificationCompat.Builder(mContext);
        notif.setTicker("Notification ticker")
             .setContentTitle("Vinceri")
             .setContentText("Ha recibido una oferta de trabajo")
             .setAutoCancel(true);
        //create notification from builder
        Notification notification = notif.build();
        mNotificationManager.notify(0, mBuilder.buildNotification(content));

只有在调用 notify 时才会发生。

android.app.RemoteServiceException: Bad notification posted from package com.java: Couldn't create icon: StatusBarIcon(pkg=com.java id=0x1 level=0 visible=true num=0 )
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1264)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4493)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
        at dalvik.system.NativeStart.main(Native Method)

最佳答案

在你的代码中添加这一行

notif.setSmallIcon(R.drawable.alarm);

确保闹钟图标应该在可绘制文件夹上

关于java - android 通知 - RemoteServiceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18918336/

相关文章:

android - 带有操作按钮的 Flutter 本地通知

android - 如何在 ListView 中由用户删除 Android 应用程序中 Sqlite 数据库中的一行

java - 点击推送通知后新 Activity 未打开

android - Firebase 使用 Node Js 函数通知未在 android 中接收,但它直接从 firebase 面板工作

android - Android应用程序和网络服务之间的身份验证+ facebook登录

android - 打开通知时出现空指针异常

java - 奇怪的安卓异常

java - 使用环境变量作为 CATALINA_HOME 的属性占位符

java - 无法比较 AJAX 调用返回的字符串

java - JFileChooser 作为 JInternalFrame