如何在android lollipop版本上设置通知图标

时间:2015-04-15 07:22:59

标签: android notifications

我正在使用此代码进行通知。它适用于所有版本,但在棒棒糖中,它会显示白色图标代替我的通知图标。

  private void sendNotification(String msg) {
    //Notification notifyObj = null;
    mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MenuActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.appicon)
    .setContentTitle("New Notification")// Vibration
    .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
    .setLights(Color.RED, 3000, 3000)
    .setWhen(System.currentTimeMillis())
    .setStyle(new NotificationCompat.BigTextStyle()
    .bigText(msg))
    .setContentText(msg);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

1 个答案:

答案 0 :(得分:0)

在设置小图标之前,您需要检查SDK版本。

而不是     .setSmallIcon(R.drawable.appicon) 使用     .setSmallIcon(CallNotiIcon())

在CallNotiIcon方法中,使用此

private int CallNotiIcon() {
boolean Icon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
return Icon ? R.drawable.appicon : R.drawable.<NEW ICON FOR LOLIPOP>;
}

请务必核对http://developer.android.com/design/style/iconography.html