2016-06-13 4 views
1

私のAndroidアプリには小さな問題があります。 FCMから通知を受け取り、プッシュ通知として表示します。これまでのところすべてが機能していますが、奇妙な問題は、アイコンが白く、時にはカラフルなことがあることです。Androidの通知アイコンの色が時には白く、時にはカラフルです

アプリが画面上で開いていて、この瞬間にプッシュ通知を受け取ると、カラフルなプッシュ通知が画面上部に表示されます。

アプリが終了すると、プッシュ通知が白いアイコンで表示されます。

私はscreenhot付属している:ここで Screenshot

は、プッシュ通知が作成されたコードスニペット、次のとおりです。

 Notification.Builder notificationBuilder = new Notification.Builder(this) 
      .setSmallIcon(android.R.drawable.ic_dialog_alert) 
      .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) 
      .setAutoCancel(true) 
      .setVisibility(Notification.VISIBILITY_PUBLIC) 
      .setPriority(Notification.PRIORITY_HIGH) 
      .setColor(Color.parseColor("#83c3ed")) 
      .setLights(Color.RED, 1000, 500) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 
    Notification.InboxStyle inboxStyle = new Notification.InboxStyle(); 
    inboxStyle.setBigContentTitle("WetterApp"); 
    inboxStyle.addLine(notification.getTitle()); 
    inboxStyle.addLine(notification.getBody()); 
    notificationBuilder.setStyle(inboxStyle); 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(0, notificationBuilder.build()); 

私のモバイルデバイスは、Android 6.0.1、私のSDKバージョンがされています23.

ありがとうございます。

答えて

1

はまあ、私はこの問題は、別の何かだったと思います。通知を作成するための私のコードは、アプリケーションが画面上で開いているときにのみ呼び出されます。通知を受け取ってアプリが終了すると、その通知はAndroidシステムによって自動的に処理されます。

私はFCMサーバーに送信される通知に色を設定する必要がありました:

$data = [ 
     'notification' => [ 
      'title' => 'Warnung: Wohnzimmer', 
      'text' => 'Innen: 20,3°C Außen: 24,5°C, Tendenz: -0,2°C', 
      'color' => '#83c3ed', 
      'sound' => 'default' 
     ], 
     'to' => '/topics/testNotification' 
    ]; 

アプリを閉じたときに今、私はまた、アプリ内で水色の背景のアイコンを取得します。

-1

もっと良い解決策は、アプリにシルエットアイコンを追加し、Android Lollipopを搭載している場合に使用することです。例えば

Notification notification = new Notification.Builder(context) 
      .setAutoCancel(true) 
      .setContentTitle("My notification") 
      .setContentText("Look, white in Lollipop, else color!") 
      .setSmallIcon(getNotificationIcon()) 
      .build(); 

    return notification; 

そして、getNotificationIcon方法で:

private int getNotificationIcon() { 
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
    return useWhiteIcon ? R.drawable.icon_silhouette : R.drawable.ic_launcher; 
} 
+0

あなたはAndroidのすべてのバージョンでシルエットを使用していたはずです - アプリアイコンは、使用するのに適した小さなアイコンではありませんでした。 – ianhanniballake

+2

少なくとも、http://stackoverflow.com/a/29207365/976367からの回答があることを述べてください –

0

あなたのアイコンを作成するには、Googleのguideに従って、それはあまりにもステータスバーに発生していることはおそらくです。その後

、これを試してみてください。

NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 
      builder.setTicker(context.getResources().getString(R.string.app_name)); 
      builder.setSmallIcon(R.mipmap.ic_your_status_bar_logo); 
      builder.setAutoCancel(true); 
      builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); 
      builder.setContentIntent(pendingIntent);   
     builder.setContentTitle(
context.getResources().getString(R.string.app_name)); 
      builder.setContentText(message); 
      builder.setDefaults(Notification.DEFAULT_SOUND); 
      builder.setPriority(NotificationCompat.PRIORITY_HIGH); 
      builder.setColor(ContextCompat.getColor(context, R.color.color_primary)); 
      NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
      nm.notify(NOTIFICATION_ID, builder.build()); 
関連する問題