-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotification.java
More file actions
5704 lines (5077 loc) · 213 KB
/
Copy pathNotification.java
File metadata and controls
5704 lines (5077 loc) · 213 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.session.MediaSession;
import android.net.Uri;
import android.os.BadParcelableException;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Log;
import android.util.MathUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.RemoteViews;
import com.android.internal.R;
import com.android.internal.util.NotificationColorUtil;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* A class that represents how a persistent notification is to be presented to
* the user using the {@link android.app.NotificationManager}.
*
* <p>The {@link Notification.Builder Notification.Builder} has been added to make it
* easier to construct Notifications.</p>
*
* <div class="special reference">
* <h3>Developer Guides</h3>
* <p>For a guide to creating notifications, read the
* <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a>
* developer guide.</p>
* </div>
*/
public class Notification implements Parcelable
{
private static final String TAG = "Notification";
/**
* An activity that provides a user interface for adjusting notification preferences for its
* containing application. Optional but recommended for apps that post
* {@link android.app.Notification Notifications}.
*/
@SdkConstant(SdkConstantType.INTENT_CATEGORY)
public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES
= "android.intent.category.NOTIFICATION_PREFERENCES";
/**
* Use all default values (where applicable).
*/
public static final int DEFAULT_ALL = ~0;
/**
* Use the default notification sound. This will ignore any given
* {@link #sound}.
*
* <p>
* A notification that is noisy is more likely to be presented as a heads-up notification.
* </p>
*
* @see #defaults
*/
public static final int DEFAULT_SOUND = 1;
/**
* Use the default notification vibrate. This will ignore any given
* {@link #vibrate}. Using phone vibration requires the
* {@link android.Manifest.permission#VIBRATE VIBRATE} permission.
*
* <p>
* A notification that vibrates is more likely to be presented as a heads-up notification.
* </p>
*
* @see #defaults
*/
public static final int DEFAULT_VIBRATE = 2;
/**
* Use the default notification lights. This will ignore the
* {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or
* {@link #ledOnMS}.
*
* @see #defaults
*/
public static final int DEFAULT_LIGHTS = 4;
/**
* Maximum length of CharSequences accepted by Builder and friends.
*
* <p>
* Avoids spamming the system with overly large strings such as full e-mails.
*/
private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024;
/**
* A timestamp related to this notification, in milliseconds since the epoch.
*
* Default value: {@link System#currentTimeMillis() Now}.
*
* Choose a timestamp that will be most relevant to the user. For most finite events, this
* corresponds to the time the event happened (or will happen, in the case of events that have
* yet to occur but about which the user is being informed). Indefinite events should be
* timestamped according to when the activity began.
*
* Some examples:
*
* <ul>
* <li>Notification of a new chat message should be stamped when the message was received.</li>
* <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li>
* <li>Notification of a completed file download should be stamped when the download finished.</li>
* <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li>
* <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time.
* <li>Notification of an ongoing countdown timer should be stamped with the timer's end time.
* </ul>
*
*/
public long when;
/**
* The resource id of a drawable to use as the icon in the status bar.
*
* @deprecated Use {@link Builder#setSmallIcon(Icon)} instead.
*/
@Deprecated
@DrawableRes
public int icon;
/**
* If the icon in the status bar is to have more than one level, you can set this. Otherwise,
* leave it at its default value of 0.
*
* @see android.widget.ImageView#setImageLevel
* @see android.graphics.drawable.Drawable#setLevel
*/
public int iconLevel;
/**
* The number of events that this notification represents. For example, in a new mail
* notification, this could be the number of unread messages.
*
* The system may or may not use this field to modify the appearance of the notification. For
* example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was
* superimposed over the icon in the status bar. Starting with
* {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by
* {@link Notification.Builder} has displayed the number in the expanded notification view.
*
* If the number is 0 or negative, it is never shown.
*/
public int number;
/**
* The intent to execute when the expanded status entry is clicked. If
* this is an activity, it must include the
* {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires
* that you take care of task management as described in the
* <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back
* Stack</a> document. In particular, make sure to read the notification section
* <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling
* Notifications</a> for the correct ways to launch an application from a
* notification.
*/
public PendingIntent contentIntent;
/**
* The intent to execute when the notification is explicitly dismissed by the user, either with
* the "Clear All" button or by swiping it away individually.
*
* This probably shouldn't be launching an activity since several of those will be sent
* at the same time.
*/
public PendingIntent deleteIntent;
/**
* An intent to launch instead of posting the notification to the status bar.
*
* <p>
* The system UI may choose to display a heads-up notification, instead of
* launching this intent, while the user is using the device.
* </p>
*
* @see Notification.Builder#setFullScreenIntent
*/
public PendingIntent fullScreenIntent;
/**
* Text that summarizes this notification for accessibility services.
*
* As of the L release, this text is no longer shown on screen, but it is still useful to
* accessibility services (where it serves as an audible announcement of the notification's
* appearance).
*
* @see #tickerView
*/
public CharSequence tickerText;
/**
* Formerly, a view showing the {@link #tickerText}.
*
* No longer displayed in the status bar as of API 21.
*/
@Deprecated
public RemoteViews tickerView;
/**
* The view that will represent this notification in the expanded status bar.
*/
public RemoteViews contentView;
/**
* A large-format version of {@link #contentView}, giving the Notification an
* opportunity to show more detail. The system UI may choose to show this
* instead of the normal content view at its discretion.
*/
public RemoteViews bigContentView;
/**
* A medium-format version of {@link #contentView}, providing the Notification an
* opportunity to add action buttons to contentView. At its discretion, the system UI may
* choose to show this as a heads-up notification, which will pop up so the user can see
* it without leaving their current activity.
*/
public RemoteViews headsUpContentView;
/**
* A large bitmap to be shown in the notification content area.
*
* @deprecated Use {@link Builder#setLargeIcon(Icon)} instead.
*/
@Deprecated
public Bitmap largeIcon;
/**
* The sound to play.
*
* <p>
* A notification that is noisy is more likely to be presented as a heads-up notification.
* </p>
*
* <p>
* To play the default notification sound, see {@link #defaults}.
* </p>
*/
public Uri sound;
/**
* Use this constant as the value for audioStreamType to request that
* the default stream type for notifications be used. Currently the
* default stream type is {@link AudioManager#STREAM_NOTIFICATION}.
*
* @deprecated Use {@link #audioAttributes} instead.
*/
@Deprecated
public static final int STREAM_DEFAULT = -1;
/**
* The audio stream type to use when playing the sound.
* Should be one of the STREAM_ constants from
* {@link android.media.AudioManager}.
*
* @deprecated Use {@link #audioAttributes} instead.
*/
@Deprecated
public int audioStreamType = STREAM_DEFAULT;
/**
* The default value of {@link #audioAttributes}.
*/
public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
/**
* The {@link AudioAttributes audio attributes} to use when playing the sound.
*/
public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT;
/**
* The pattern with which to vibrate.
*
* <p>
* To vibrate the default pattern, see {@link #defaults}.
* </p>
*
* <p>
* A notification that vibrates is more likely to be presented as a heads-up notification.
* </p>
*
* @see android.os.Vibrator#vibrate(long[],int)
*/
public long[] vibrate;
/**
* The color of the led. The hardware will do its best approximation.
*
* @see #FLAG_SHOW_LIGHTS
* @see #flags
*/
@ColorInt
public int ledARGB;
/**
* The number of milliseconds for the LED to be on while it's flashing.
* The hardware will do its best approximation.
*
* @see #FLAG_SHOW_LIGHTS
* @see #flags
*/
public int ledOnMS;
/**
* The number of milliseconds for the LED to be off while it's flashing.
* The hardware will do its best approximation.
*
* @see #FLAG_SHOW_LIGHTS
* @see #flags
*/
public int ledOffMS;
/**
* Specifies which values should be taken from the defaults.
* <p>
* To set, OR the desired from {@link #DEFAULT_SOUND},
* {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default
* values, use {@link #DEFAULT_ALL}.
* </p>
*/
public int defaults;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if you want the LED on for this notification.
* <ul>
* <li>To turn the LED off, pass 0 in the alpha channel for colorARGB
* or 0 for both ledOnMS and ledOffMS.</li>
* <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li>
* <li>To flash the LED, pass the number of milliseconds that it should
* be on and off to ledOnMS and ledOffMS.</li>
* </ul>
* <p>
* Since hardware varies, you are not guaranteed that any of the values
* you pass are honored exactly. Use the system defaults (TODO) if possible
* because they will be set to values that work on any given hardware.
* <p>
* The alpha channel must be set for forward compatibility.
*
*/
public static final int FLAG_SHOW_LIGHTS = 0x00000001;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if this notification is in reference to something that is ongoing,
* like a phone call. It should not be set if this notification is in
* reference to something that happened at a particular point in time,
* like a missed phone call.
*/
public static final int FLAG_ONGOING_EVENT = 0x00000002;
/**
* Bit to be bitwise-ored into the {@link #flags} field that if set,
* the audio will be repeated until the notification is
* cancelled or the notification window is opened.
*/
public static final int FLAG_INSISTENT = 0x00000004;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if you would only like the sound, vibrate and ticker to be played
* if the notification was not already showing.
*/
public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if the notification should be canceled when it is clicked by the
* user.
*/
public static final int FLAG_AUTO_CANCEL = 0x00000010;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if the notification should not be canceled when the user clicks
* the Clear all button.
*/
public static final int FLAG_NO_CLEAR = 0x00000020;
/**
* Bit to be bitwise-ored into the {@link #flags} field that should be
* set if this notification represents a currently running service. This
* will normally be set for you by {@link Service#startForeground}.
*/
public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;
/**
* Obsolete flag indicating high-priority notifications; use the priority field instead.
*
* @deprecated Use {@link #priority} with a positive value.
*/
public static final int FLAG_HIGH_PRIORITY = 0x00000080;
/**
* Bit to be bitswise-ored into the {@link #flags} field that should be
* set if this notification is relevant to the current device only
* and it is not recommended that it bridge to other devices.
*/
public static final int FLAG_LOCAL_ONLY = 0x00000100;
/**
* Bit to be bitswise-ored into the {@link #flags} field that should be
* set if this notification is the group summary for a group of notifications.
* Grouped notifications may display in a cluster or stack on devices which
* support such rendering. Requires a group key also be set using {@link Builder#setGroup}.
*/
public static final int FLAG_GROUP_SUMMARY = 0x00000200;
public int flags;
/** @hide */
@IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX})
@Retention(RetentionPolicy.SOURCE)
public @interface Priority {}
/**
* Default notification {@link #priority}. If your application does not prioritize its own
* notifications, use this value for all notifications.
*/
public static final int PRIORITY_DEFAULT = 0;
/**
* Lower {@link #priority}, for items that are less important. The UI may choose to show these
* items smaller, or at a different position in the list, compared with your app's
* {@link #PRIORITY_DEFAULT} items.
*/
public static final int PRIORITY_LOW = -1;
/**
* Lowest {@link #priority}; these items might not be shown to the user except under special
* circumstances, such as detailed notification logs.
*/
public static final int PRIORITY_MIN = -2;
/**
* Higher {@link #priority}, for more important notifications or alerts. The UI may choose to
* show these items larger, or at a different position in notification lists, compared with
* your app's {@link #PRIORITY_DEFAULT} items.
*/
public static final int PRIORITY_HIGH = 1;
/**
* Highest {@link #priority}, for your application's most important items that require the
* user's prompt attention or input.
*/
public static final int PRIORITY_MAX = 2;
/**
* Relative priority for this notification.
*
* Priority is an indication of how much of the user's valuable attention should be consumed by
* this notification. Low-priority notifications may be hidden from the user in certain
* situations, while the user might be interrupted for a higher-priority notification. The
* system will make a determination about how to interpret this priority when presenting
* the notification.
*
* <p>
* A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented
* as a heads-up notification.
* </p>
*
*/
@Priority
public int priority;
/**
* Accent color (an ARGB integer like the constants in {@link android.graphics.Color})
* to be applied by the standard Style templates when presenting this notification.
*
* The current template design constructs a colorful header image by overlaying the
* {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are
* ignored.
*/
@ColorInt
public int color = COLOR_DEFAULT;
/**
* Special value of {@link #color} telling the system not to decorate this notification with
* any special color but instead use default colors when presenting this notification.
*/
@ColorInt
public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT
/**
* Sphere of visibility of this notification, which affects how and when the SystemUI reveals
* the notification's presence and contents in untrusted situations (namely, on the secure
* lockscreen).
*
* The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always
* done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are
* shown in all situations, but the contents are only available if the device is unlocked for
* the appropriate user.
*
* A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification
* can be read even in an "insecure" context (that is, above a secure lockscreen).
* To modify the public version of this notification—for example, to redact some portions—see
* {@link Builder#setPublicVersion(Notification)}.
*
* Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon
* and ticker until the user has bypassed the lockscreen.
*/
public int visibility;
/**
* Notification visibility: Show this notification in its entirety on all lockscreens.
*
* {@see #visibility}
*/
public static final int VISIBILITY_PUBLIC = 1;
/**
* Notification visibility: Show this notification on all lockscreens, but conceal sensitive or
* private information on secure lockscreens.
*
* {@see #visibility}
*/
public static final int VISIBILITY_PRIVATE = 0;
/**
* Notification visibility: Do not reveal any part of this notification on a secure lockscreen.
*
* {@see #visibility}
*/
public static final int VISIBILITY_SECRET = -1;
/**
* Notification category: incoming call (voice or video) or similar synchronous communication request.
*/
public static final String CATEGORY_CALL = "call";
/**
* Notification category: incoming direct message (SMS, instant message, etc.).
*/
public static final String CATEGORY_MESSAGE = "msg";
/**
* Notification category: asynchronous bulk message (email).
*/
public static final String CATEGORY_EMAIL = "email";
/**
* Notification category: calendar event.
*/
public static final String CATEGORY_EVENT = "event";
/**
* Notification category: promotion or advertisement.
*/
public static final String CATEGORY_PROMO = "promo";
/**
* Notification category: alarm or timer.
*/
public static final String CATEGORY_ALARM = "alarm";
/**
* Notification category: progress of a long-running background operation.
*/
public static final String CATEGORY_PROGRESS = "progress";
/**
* Notification category: social network or sharing update.
*/
public static final String CATEGORY_SOCIAL = "social";
/**
* Notification category: error in background operation or authentication status.
*/
public static final String CATEGORY_ERROR = "err";
/**
* Notification category: media transport control for playback.
*/
public static final String CATEGORY_TRANSPORT = "transport";
/**
* Notification category: system or device status update. Reserved for system use.
*/
public static final String CATEGORY_SYSTEM = "sys";
/**
* Notification category: indication of running background service.
*/
public static final String CATEGORY_SERVICE = "service";
/**
* Notification category: a specific, timely recommendation for a single thing.
* For example, a news app might want to recommend a news story it believes the user will
* want to read next.
*/
public static final String CATEGORY_RECOMMENDATION = "recommendation";
/**
* Notification category: ongoing information about device or contextual status.
*/
public static final String CATEGORY_STATUS = "status";
/**
* Notification category: user-scheduled reminder.
*/
public static final String CATEGORY_REMINDER = "reminder";
/**
* One of the predefined notification categories (see the <code>CATEGORY_*</code> constants)
* that best describes this Notification. May be used by the system for ranking and filtering.
*/
public String category;
private String mGroupKey;
/**
* Get the key used to group this notification into a cluster or stack
* with other notifications on devices which support such rendering.
*/
public String getGroup() {
return mGroupKey;
}
private String mSortKey;
/**
* Get a sort key that orders this notification among other notifications from the
* same package. This can be useful if an external sort was already applied and an app
* would like to preserve this. Notifications will be sorted lexicographically using this
* value, although providing different priorities in addition to providing sort key may
* cause this value to be ignored.
*
* <p>This sort key can also be used to order members of a notification group. See
* {@link Builder#setGroup}.
*
* @see String#compareTo(String)
*/
public String getSortKey() {
return mSortKey;
}
/**
* Additional semantic data to be carried around with this Notification.
* <p>
* The extras keys defined here are intended to capture the original inputs to {@link Builder}
* APIs, and are intended to be used by
* {@link android.service.notification.NotificationListenerService} implementations to extract
* detailed information from notification objects.
*/
public Bundle extras = new Bundle();
/**
* {@link #extras} key: this is the title of the notification,
* as supplied to {@link Builder#setContentTitle(CharSequence)}.
*/
public static final String EXTRA_TITLE = "android.title";
/**
* {@link #extras} key: this is the title of the notification when shown in expanded form,
* e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}.
*/
public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big";
/**
* {@link #extras} key: this is the main text payload, as supplied to
* {@link Builder#setContentText(CharSequence)}.
*/
public static final String EXTRA_TEXT = "android.text";
/**
* {@link #extras} key: this is a third line of text, as supplied to
* {@link Builder#setSubText(CharSequence)}.
*/
public static final String EXTRA_SUB_TEXT = "android.subText";
/**
* {@link #extras} key: this is a small piece of additional text as supplied to
* {@link Builder#setContentInfo(CharSequence)}.
*/
public static final String EXTRA_INFO_TEXT = "android.infoText";
/**
* {@link #extras} key: this is a line of summary information intended to be shown
* alongside expanded notifications, as supplied to (e.g.)
* {@link BigTextStyle#setSummaryText(CharSequence)}.
*/
public static final String EXTRA_SUMMARY_TEXT = "android.summaryText";
/**
* {@link #extras} key: this is the longer text shown in the big form of a
* {@link BigTextStyle} notification, as supplied to
* {@link BigTextStyle#bigText(CharSequence)}.
*/
public static final String EXTRA_BIG_TEXT = "android.bigText";
/**
* {@link #extras} key: this is the resource ID of the notification's main small icon, as
* supplied to {@link Builder#setSmallIcon(int)}.
*/
public static final String EXTRA_SMALL_ICON = "android.icon";
/**
* {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the
* notification payload, as
* supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}.
*/
public static final String EXTRA_LARGE_ICON = "android.largeIcon";
/**
* {@link #extras} key: this is a bitmap to be used instead of the one from
* {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is
* shown in its expanded form, as supplied to
* {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}.
*/
public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big";
/**
* {@link #extras} key: this is the progress value supplied to
* {@link Builder#setProgress(int, int, boolean)}.
*/
public static final String EXTRA_PROGRESS = "android.progress";
/**
* {@link #extras} key: this is the maximum value supplied to
* {@link Builder#setProgress(int, int, boolean)}.
*/
public static final String EXTRA_PROGRESS_MAX = "android.progressMax";
/**
* {@link #extras} key: whether the progress bar is indeterminate, supplied to
* {@link Builder#setProgress(int, int, boolean)}.
*/
public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate";
/**
* {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically
* a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to
* {@link Builder#setUsesChronometer(boolean)}.
*/
public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer";
/**
* {@link #extras} key: whether {@link #when} should be shown,
* as supplied to {@link Builder#setShowWhen(boolean)}.
*/
public static final String EXTRA_SHOW_WHEN = "android.showWhen";
/**
* {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded
* notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}.
*/
public static final String EXTRA_PICTURE = "android.picture";
/**
* {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded
* notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}.
*/
public static final String EXTRA_TEXT_LINES = "android.textLines";
/**
* {@link #extras} key: A string representing the name of the specific
* {@link android.app.Notification.Style} used to create this notification.
*/
public static final String EXTRA_TEMPLATE = "android.template";
/**
* {@link #extras} key: A String array containing the people that this notification relates to,
* each of which was supplied to {@link Builder#addPerson(String)}.
*/
public static final String EXTRA_PEOPLE = "android.people";
/**
* {@link #extras} key: used to provide hints about the appropriateness of
* displaying this notification as a heads-up notification.
* @hide
*/
public static final String EXTRA_AS_HEADS_UP = "headsup";
/**
* Allow certain system-generated notifications to appear before the device is provisioned.
* Only available to notifications coming from the android package.
* @hide
*/
public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup";
/**
* {@link #extras} key: A
* {@link android.content.ContentUris content URI} pointing to an image that can be displayed
* in the background when the notification is selected. The URI must point to an image stream
* suitable for passing into
* {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream)
* BitmapFactory.decodeStream}; all other content types will be ignored. The content provider
* URI used for this purpose must require no permissions to read the image data.
*/
public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri";
/**
* {@link #extras} key: A
* {@link android.media.session.MediaSession.Token} associated with a
* {@link android.app.Notification.MediaStyle} notification.
*/
public static final String EXTRA_MEDIA_SESSION = "android.mediaSession";
/**
* {@link #extras} key: the indices of actions to be shown in the compact view,
* as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}.
*/
public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions";
/**
* {@link #extras} key: the user that built the notification.
*
* @hide
*/
public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId";
/**
* Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be
* displayed in the heads up space.
*
* <p>
* If this notification has a {@link #fullScreenIntent}, then it will always launch the
* full-screen intent when posted.
* </p>
* @hide
*/
public static final int HEADS_UP_NEVER = 0;
/**
* Default value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification may be
* displayed as a heads up.
* @hide
*/
public static final int HEADS_UP_ALLOWED = 1;
/**
* Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification is a
* good candidate for display as a heads up.
* @hide
*/
public static final int HEADS_UP_REQUESTED = 2;
private Icon mSmallIcon;
private Icon mLargeIcon;
/**
* Structure to encapsulate a named action that can be shown as part of this notification.
* It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is
* selected by the user.
* <p>
* Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}
* or {@link Notification.Builder#addAction(Notification.Action)}
* to attach actions.
*/
public static class Action implements Parcelable {
private final Bundle mExtras;
private Icon mIcon;
private final RemoteInput[] mRemoteInputs;
/**
* Small icon representing the action.
*
* @deprecated Use {@link Action#getIcon()} instead.
*/
@Deprecated
public int icon;
/**
* Title of the action.
*/
public CharSequence title;
/**
* Intent to send when the user invokes this action. May be null, in which case the action
* may be rendered in a disabled presentation by the system UI.
*/
public PendingIntent actionIntent;
private Action(Parcel in) {
if (in.readInt() != 0) {
mIcon = Icon.CREATOR.createFromParcel(in);
if (mIcon.getType() == Icon.TYPE_RESOURCE) {
icon = mIcon.getResId();
}
}
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
if (in.readInt() == 1) {
actionIntent = PendingIntent.CREATOR.createFromParcel(in);
}
mExtras = in.readBundle();
mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR);
}
/**
* @deprecated Use {@link android.app.Notification.Action.Builder}.
*/
@Deprecated
public Action(int icon, CharSequence title, PendingIntent intent) {
this(Icon.createWithResource("", icon), title, intent, new Bundle(), null);
}
private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras,
RemoteInput[] remoteInputs) {
this.mIcon = icon;
this.title = title;
this.actionIntent = intent;
this.mExtras = extras != null ? extras : new Bundle();
this.mRemoteInputs = remoteInputs;
}
/**
* Return an icon representing the action.
*/
public Icon getIcon() {
if (mIcon == null && icon != 0) {
// you snuck an icon in here without using the builder; let's try to keep it
mIcon = Icon.createWithResource("", icon);
}
return mIcon;
}
/**
* Get additional metadata carried around with this Action.
*/
public Bundle getExtras() {
return mExtras;
}
/**
* Get the list of inputs to be collected from the user when this action is sent.
* May return null if no remote inputs were added.
*/
public RemoteInput[] getRemoteInputs() {
return mRemoteInputs;
}
/**
* Builder class for {@link Action} objects.
*/
public static final class Builder {
private final Icon mIcon;
private final CharSequence mTitle;
private final PendingIntent mIntent;
private final Bundle mExtras;
private ArrayList<RemoteInput> mRemoteInputs;
/**
* Construct a new builder for {@link Action} object.
* @param icon icon to show for this action