5
A
回答
2
最小用法:
NotificatorFacade nb = new NotificatorFacade(context);
nb.show(R.drawable.icon, "tickerText", new Date().getTime(),
"contentTitle", "contentText", ERROR_NOTIFICATION_ID);
源:
package my.tools.android.notification; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.net.Uri; public class NotificatorBuilder { private final Context context; private Intent intent; private Integer flags; private Integer defaults; private Uri sound; public NotificatorBuilder(Context context) { this.context = context; } /** * sets the flags for Notification.defaults * * @param defaults */ public void setDefaults(int defaults) { this.defaults = defaults; } /** * displays the notification with the given parameters it sets * notification.flags|=Notification.FLAG_AUTO_CANCEL when intent (setIntent) * is null the setIntent functionality was not tested * * @see http * ://developer.android.com/guide/topics/ui/notifiers/notifications. * html * @param iconDrawable the icon * @param tickerText * @param when * @param contentTitle * @param contentText * @param NOTIFICATION_ID this id is used for later identification */ public void show(int iconDrawable, CharSequence tickerText, long when, CharSequence contentTitle, CharSequence contentText, int NOTIFICATION_ID) { // Get a reference to the NotificationManager: String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(ns); // Instantiate the Notification: Notification notification = new Notification(iconDrawable, tickerText, when); // Define the Notification's expanded message and Intent: if (sound == null) { notification.sound = sound; } if (flags != null) { notification.flags = flags; } if (defaults != null) { notification.defaults = defaults; } // if intent null create one and set the FLAG_AUTO_CANCEL flag EXTENDS // FLAGS!!! if (intent == null) { setIntent(new Intent(context, NotificatorBuilder.class)); notification.flags |= Notification.FLAG_AUTO_CANCEL; } PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(NOTIFICATION_ID, notification); } /** * sets the flags for notification usage: NotificatorBuilder nb = new * NotificatorBuilder(context); * nb.setFlags(Notification.DEFAULT_VIBRATE|Notification.FLAG_INSISTENT); * * @param flags */ public void setFlags(int flags) { this.flags = flags; } /** * sets the intent for * * PendingIntent contentIntent = PendingIntent.getActivity(context, 0, * intent, 0); notification.setLatestEventInfo(context, contentTitle, * contentText,contentIntent); this functionality was not tested * * @param intent */ public void setIntent(Intent intent) { this.intent = intent; } /** * sets the sound for the notification was not tested but should work usage * for default notification call the method :setDefaults(Notification.DEFAULT_SOUND); * usage: * To use a different sound with your notifications, pass a Uri reference to * the sound field. The following example uses a known audio file saved to * the device SD card: * notification.sound = * Uri.parse("file:///sdcard/notification/ringer.mp3"); * * In the next example, the audio file is chosen from the internal * MediaStore's ContentProvider: notification.sound = * Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6"); * * @param sound */ public void setSound(Uri sound) { this.sound = sound; } }
相關問題
- 1. 在服務狀態欄中創建通知的問題Android
- 2. 如何使addProximityAlert()在狀態欄中創建通知?
- 3. Android如何攔截狀態欄通知?
- 4. Android狀態欄通知
- 5. Phonegap - Android - 狀態欄通知
- 6. Android狀態欄通知 - 通過任何方式通知狀態欄(烤麪包)通過狀態欄?
- 7. 如何在右側創建通知\狀態欄圖標?
- 8. PhoneGap的Android狀態欄通知例如
- 9. 狀態欄android中的通知
- 10. 如何避免相同的通知在android狀態欄多次創建?
- 11. 創建一個永久通知和防止通知狀態欄
- 12. Android:靜態狀態欄通知
- 13. 狀態欄通知
- 14. 狀態欄通知
- 15. 如何使用狀態欄文本創建通知(無圖標)
- 16. 如何在Android狀態欄中隱藏通知圖標?
- 17. Android:我如何從由狀態欄通知創建的PendingIntent訪問AsyncTask?
- 18. 在狀態欄和狀態通知(正在進行)中創建動態更改圖標Android
- 19. Android - 增量狀態欄通知圖標
- 20. Phonegap狀態欄通知,Android,iOS
- 21. 每天更改android狀態欄通知
- 22. Android狀態欄multiline通知API 14
- 23. 狀態通知欄上的徽標Android
- 24. android狀態欄沒有通知彈出
- 25. Android狀態欄通知不加載
- 26. 如何處理狀態欄通知?
- 27. 如何在Android手機狀態欄上添加通知圖標?
- 28. 如何使用android phonegap在狀態欄顯示通知數
- 29. Android如何在狀態欄上隱藏NotificationCompat.Builder通知的圖標?
- 30. 如何在ACTION_BATTERY_LOW時在通知欄中創建通知?