2017-08-21 2 views
-3

In einigen Geräten erhalte ich eine leere (weiße) Benachrichtigung wie angehängter Screenshot. Und in einigen Geräten funktioniert es gut. Bitte helfen Sie mir, dieses Problem zu lösen. enter image description hereLeere Benachrichtigung auf einem Android-Gerät erhalten

Intent intent = new Intent(ctx, NotificationDetailActivity.class); 
      intent.putExtra("id", id); 
      PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 
        PendingIntent.FLAG_ONE_SHOT); 
      Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
      NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); 
      builder.setTicker(getResources().getString(R.string.app_name)); 
      // Sets the small icon for the ticker 
      builder.setSmallIcon(getNotificationIcon()); 
      builder.setLargeIcon(result); 
      builder.setColor(getResources().getColor(R.color.colorPrimary)); 
      builder.setContentTitle(title); 
      builder.setContentText(messageBody); 
      builder.setSound(defaultSoundUri); 
      builder.setContentIntent(pendingIntent); 
      builder.setAutoCancel(true); 
      Notification notification = builder.build(); 
      RemoteViews expandedView = 
        new RemoteViews(ctx.getPackageName(), R.layout.custom_notification); 
      if (Build.VERSION.SDK_INT >= 16) 
      { 
       // Inflate and set the layout for the expanded notification view 
       expandedView.setImageViewBitmap(R.id.imgBigImage, result); 
       notification.bigContentView = expandedView; 
       NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
       nm.notify(Integer.parseInt(id), notification); 
      } else { 
       NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(ctx) 
         .setSmallIcon(getNotificationIcon()) 
         .setLargeIcon(result) 
         .setColor(getResources().getColor(R.color.colorPrimary)) 
         .setContentTitle(title) 
         .setContentText(messageBody) 
         .setAutoCancel(true) 
         .setSound(defaultSoundUri) 
         .setContentIntent(pendingIntent); 
       NotificationManager notificationManager = 
         (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
       notificationManager.notify(Integer.parseInt(id), notificationBuilder.build()); 
      } 
+0

Lolipop und oben Version Sie das Problem bekommen. Ist es nicht? – Piyush

+0

Fügen Sie Ihren Benachrichtigungscode hier hinzu. –

+0

Bitte fügen Sie Ihren Code –

Antwort

0

auf diese Weise zu setBigContentView-NotificationCompat.Builder Versuchen Sie, ob es funktioniert: -

Intent intent = new Intent(ctx, NotificationDetailActivity.class); 
    intent.putExtra("id", id); 
    PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 0, intent, 
      PendingIntent.FLAG_ONE_SHOT); 
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); 
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
//  Notification notification = builder.build(); 
     RemoteViews expandedView = 
       new RemoteViews(ctx.getPackageName(), R.layout.custom_notification); 
     if (Build.VERSION.SDK_INT >= 16) 
     { 
      builder.setTicker(getResources().getString(R.string.app_name)); 
      // Sets the small icon for the ticker 
      builder.setSmallIcon(getNotificationIcon()); 
      builder.setLargeIcon(result); 
      builder.setColor(getResources().getColor(R.color.colorPrimary)); 
      builder.setContentTitle(title); 
      builder.setContentText(messageBody); 
      builder.setSound(defaultSoundUri); 
      builder.setContentIntent(pendingIntent); 
      builder.setAutoCancel(true); 
      // Inflate and set the layout for the expanded notification view 
      expandedView.setImageViewBitmap(R.id.imgBigImage, result); 
//   notification.bigContentView = expandedView; 
      builder.setCustomBigContentView(expandedView); 
     } else { 
      builder.setSmallIcon(getNotificationIcon()); 
      builder.setLargeIcon(result); 
      builder.setColor(getResources().getColor(R.color.colorPrimary)); 
      builder.setContentTitle(title); 
      builder.setContentText(messageBody); 
      builder.setAutoCancel(true); 
      builder.setSound(defaultSoundUri); 
      builder.setContentIntent(pendingIntent); 
     } 
     nm.notify(Integer.parseInt(id), builder.build()); 
+0

Nitin Es funktioniert nicht :( –

+0

@AnkitaGuna Nun Ausgabe kann mit 'expandedView' sein. So ersten Kommentar' builder.setCustomBigContentView (expandedView); 'Linie und versuchen Sie es zu überprüfen. –

+0

Ja. In diesem Fall funktioniert einwandfrei –

Verwandte Themen