web-dev-qa-db-ja.com

通知ドロワーでアプリアイコンを通知アイコンとして設定する方法

図に示すように...
通知アイコンが表示されます(左側が赤色)。
しかし、黒い矢印で示されているようにアプリのアイコンを表示する必要があります

enter image description here

    public void notify(View view){
    notification.setSmallIcon(R.drawable.ic_stat_name);
    notification.setTicker("Welcome to ****");
    notification.setWhen(System.currentTimeMillis());
    notification.setContentTitle("abcd");
    notification.setContentText("abcd");


    Intent intent = new Intent(this, home.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setContentIntent(pendingIntent);


    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(uniqueID, notification.build());
}
23
Aditya Suresh

通知ビルダーでこのコードを試してください:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                        R.mipmap.ic_launcher))
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

Android.app.NotificationManager notificationManager =
                (Android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

大きいアイコンを設定するとうまくいきます。さらに情報がある場合は、下のコメントを参照してください

52
Manikanta

私はここで答えるのが少し遅れており、すでに答えられていることも知っていますが、Firebase Notificationを使用した簡単な修正を探してここに来ました。私のような誰かがここにアクセスすると、Firebase通知の推奨される簡単な方法でソリューションを実行できます。これは、マニフェストにメタデータを追加するだけです。

参照

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_icon"
    Android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_color"
    Android:resource="@color/colorAccent" />
49
Adam