[英]How to set notification icon on android lollipop version
我正在使用此代码进行通知。 它适用于所有版本,但在棒棒糖中均显示白色图标代替我的通知图标。
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());
}
设置小图标之前,您需要检查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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.