Android通知 - RemoteServiceException

6
我遇到了RemoteServiceException。如果我在活动的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)
1个回答

7

在你的代码中添加这一行

notif.setSmallIcon(R.drawable.alarm);

请确保警报图标应该在drawable文件夹中。

我错过了生成通知所需的必要部分。所有必要的元素应该在某个构造函数中强制执行(比如构建器)... 不确定是否有地方提到这一点。 - singhsumit

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接