2017-08-21 71 views
-3

在某些設備中,我收到了一個空白(白色)通知,如附加的屏幕截圖。在某些設備中,它工作正常。請幫我解決這個問題。 enter image description here在某些Android設備中獲取空白通知

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

棒棒糖及以上版本中,你所得到的問題。不是嗎? – Piyush

+0

在這裏添加您的申請代碼.. –

+0

請加你的代碼 –

回答

0

這種方式嘗試setBigContentViewNotificationCompat.Builder,檢查是否正常工作: -

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它不工作:( –

+0

@AnkitaGuna現在問題可能與'expandedView'。因此,第一次評論'builder.setCustomBigContentView(expandedView);'線,並嘗試檢查。 –

+0

是的。在這種情況下。工作正常。 –

相關問題