1

I want to create custom notification for that i use this code

RemoteViews remoteViews;
Intent intent;
NotificationCompat.Builder builder;
PendingIntent pIntent;

intent = new Intent(context, SarinaHome.class);
            pIntent = PendingIntent.getActivity(context, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            remoteViews = new RemoteViews(context.getPackageName(),
                    R.layout.custom_notification);

            builder = new NotificationCompat.Builder(context)
                    // Set Icon
                    .setSmallIcon(R.drawable.ic_launcher)
                            // Set Ticker Message
                    .setTicker(context.getString(R.string.app_name))
                            // Dismiss Notification
                    .setAutoCancel(true)
                            // Set PendingIntent into Notification
                    .setContentIntent(pIntent)
                            // Set RemoteViews into Notification
                    .setContent(remoteViews);
            remoteViews.setTextViewText(R.id.message_custom_notification,message+ context.getString(R.string.havenewmessage));



NotificationManager notificationmanager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);     


notificationmanager.notify(1130, builder.build());

but i give this error message:

Process: com.rad.sarina, PID: 12557
    android.app.RemoteServiceException: Bad notification posted from package com.rad.sarina: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.rad.sarina user=UserHandle{0} id=1130 tag=null score=0: Notification(pri=0 icon=7f0200b3 contentView=com.rad.sarina/0x7f030024 vibrate=null sound=null defaults=0x0 flags=0x10 when=1438512821851 ledARGB=0x0 contentIntent=Y deleteIntent=N contentTitle=N contentText=N tickerText=6 kind=[null]))
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1453)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5479)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)      

and strange thing is this code work earlier but today no.
so can any one help me?

max
  • 5,963
  • 12
  • 49
  • 80

3 Answers3

1

Exception android.app.RemoteServiceException: Bad notification posted from package com.xxxx: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.swazer.smares user=UserHandle{0} id=1 tag=null score=0: Notification(pri=0 icon=7f0201aa contentView=com.swazer.smares/0x1090069 vibrate=null sound=null defaults=0x0 flags=0x10 when=1498216158616 ledARGB=0x0 contentIntent=Y deleteIntent=N contentTitle=13 contentText=53 tickerText=N kind=[null] 2 actions))

put vectorDrawables to Notification, it is make the same exception I changed ti to image png it is worked well

Kukic Vladimir
  • 1,010
  • 4
  • 15
  • 22
ibrahim
  • 11
  • 3
-1

i found my problem and it was not in my qustion "sorry about that".
i use scroll view in my custom notification which we cannot use in custom notification "i dont know why maybe for mixed up with status menu scroll".
so do not use scroll view in custom notification

max
  • 5,963
  • 12
  • 49
  • 80
-3
Notification(pri=2 contentView=com.android.incallui/0x7f04009e vibrate=null
sound=null defaults=0x0 flags=0x2 color=0x00000000 originalPackageName=N originalUserId=0
vis=PRIVATE publicVersion=Notification(pri=0 contentView=com.android.incallui/0x7f0400aa 
vibrate=null sound=null defaults=0x0 flags=0x10 color=0x00000000 originalPackageName=N 
originalUserId=0 vis=PUBLIC))
Kahbazi
  • 14,331
  • 3
  • 45
  • 76
ali
  • 1