对于不同的项目通知android

时间:2016-12-26 07:19:48

标签: android notifications icons

我对两个不同的项目使用相同的通知图标进行firebase通知。在一个项目中,图标按原样显示,但在其他项目中,它会变为白色以进行通知。请帮忙

2 个答案:

答案 0 :(得分:0)

Use this code Implementation of Notification Builder for below and above Lollipop OS version would be:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    builder.setSmallIcon(R.drawable.icon_transperent);
} else { 
    builder.setSmallIcon(R.drawable.icon);
} 
If you want to set colored single icon for all OS version then

Solution: For colored icons, use

defaultConfig {
        applicationId "com.your.app.pkj"
        minSdkVersion xx
        targetSdkVersion 20 // < 21 (target sdk version in manifest file will be less than 21).
        versionCode x
        versionName "x.x"
    }
在app / build.gradle文件中。它将完全解决您的问题!我已通过此代码解决了我的问题。

答案 1 :(得分:0)

据我所知,图像/图标大小的问题会调整图像/图标大小。

我使用以下代码生成通知

public void showNotification(Context context) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class), 0);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.icon)
                    .setContentTitle("Notification")
                    .setContentText("Notify!!!");
    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    mBuilder.setAutoCancel(true);
    NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());

}