// 之所以用NotifcationCompat,因为这个可以直接兼容到API4 new NotificationCompat.Builder(this) .setSmallIcon(...) .setContentTitle(senderName) .setContentText(msgText) .setCategory( // CATEGORY_ALARM(alarms or timers), REMINDER(user requested reminder),EVENT,MESSAGE,CALL,EMAIL,SOCIAL,RECOMMENDATION(TV?) ) .build();
2. 尊重你的用户
1 2 3 4 5 6
// MAX(time-critical tasks, incoming calls, turn-by-turn directions) // HIGH(important communications, chats, texts, important emails) // LOW(not time sensitive, social broadcasts) // MIN(contextual or background infomation, recommendations wechther), not show when locked screen // setPriority NotificationCompat.PRIORITY_
同id的notification, 声音、振动、ticker 仅第一次
1 2 3 4 5
NotificationCompat.Builderbuilder= newNotificationCompat.Builder(c) // Set this flag if you would only like the sound, vibrate and ticker to be played if the notification is not already showing. .setOnlyAlertOnce(true) .setProgress(100, 50, false);
new Notification.Builder(this) .setSmallIcon(...) .setContentTitle(title) .setContentText(text) // started in Jelly Bean .setStyle( new Notification.BigPictureStyle() .bigPicture(photoBitmap)) .build();
// rich text? .setStyle( new Notification.BigTextStyle() .bigText(longText)) .build();