web-dev-qa-db-ja.com

android 7.0白い四角で表示される通知アイコン

以下のスニペットを使用して、Androidアプリで通知を生成しています。

private void sendNotification(String contentText, String message) {

    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.putExtra("clear","clear");
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
     Intent.FLAG_ACTIVITY_CLEAR_TASK);

   PendingIntent piResult = PendingIntent.getActivity(this, 0, resultIntent,0);

    NotificationCompat.Builder builder=new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setColor(ContextCompat.getColor(getApplicationContext(),R.color.red))
            .setContentTitle("title")
            .setContentText(message)
            .setAutoCancel(true)
            .setLargeIcon(BitmapFactory.decodeResource(getResources() 
            ,R.drawable.notification))
            .setContentIntent(piResult);

    NotificationCompat.InboxStyle notification = new NotificationCompat.InboxStyle(builder);

    int i;
    for(i=0; i<messageList.size();i++){
        notification.addLine(messageList.get(i));
    }
    notification.setBigContentTitle("title");
    notification.setSummaryText(contentText);

    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID,notification.build());
}

Android 5および6で動作しますが、Android nougatでは動作しません

6
Suresh Kumar

Androidバージョンlollpop以降、通知の変更が加えられました。小さいアイコンを指定する場合は、 このリンク に記載されている特定のサイズにする必要があります。 。

重要なのは、画像は透明であり、の色のみが含まれている必要があることです。

あなたはチェックすることができます この質問 答えを得るために

3
Ichigo Kurosaki

Android APIから docs に続く:

ステータスバーのアイコンは、透明な背景の白いピクセルで構成され、必要に応じて滑らかなエッジと内部テクスチャにアルファブレンディングが使用されます。

画像全体ですが、透明部分は白に変換されます(元々は白であるか、色があります)。

1つの解決策は、色付きのシルエットアイコンを作成することです。これにより、すべてのAndroid APIで同じ画像を使用できます。1つの例は次のアイコンです。

White image on a transparent backdrop

Androidの下位バージョンでは、黒い顔が表示されますが、最後のバージョンでは、同じ顔が白い色で表示されます。これは、透明な部分があるためです(SOは透明度を削除し、画像の ここ )からオリジナルを取得できます。

2
Alberto Méndez

このブログによると ここ

それはそれを言います

新しい通知にはアイコンが表示されないことに注意してください。代わりに、通知シェードの限られたスペースにラベル自体のためのより多くのスペースが提供されます。ただし、通知アクションアイコンは引き続き必要であり、古いバージョンのAndroidおよびAndroid Wearなどのデバイスで引き続き使用されます。

NotificationCompat.Builderとそこで利用可能な標準スタイルを使用して通知を作成している場合は、コードを変更することなく、デフォルトで新しいルックアンドフィールを取得できます。

1