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时在通知栏中创建通知?