diff options
| -rw-r--r-- | core/api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/app/Notification.java | 32 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/app/NotificationTest.java | 19 |
3 files changed, 53 insertions, 0 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index dada20eb14dc..0972f4110d0b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -6396,6 +6396,7 @@ package android.app { method public android.graphics.drawable.Icon getLargeIcon(); method @Nullable public android.content.LocusId getLocusId(); method public CharSequence getSettingsText(); + method @FlaggedApi("android.app.api_rich_ongoing") @Nullable public String getShortCriticalText(); method public String getShortcutId(); method public android.graphics.drawable.Icon getSmallIcon(); method public String getSortKey(); @@ -6719,6 +6720,7 @@ package android.app { method @NonNull public android.app.Notification.Builder setPublicVersion(android.app.Notification); method @NonNull public android.app.Notification.Builder setRemoteInputHistory(CharSequence[]); method @NonNull public android.app.Notification.Builder setSettingsText(CharSequence); + method @FlaggedApi("android.app.api_rich_ongoing") @NonNull public android.app.Notification.Builder setShortCriticalText(@Nullable String); method @NonNull public android.app.Notification.Builder setShortcutId(String); method @NonNull public android.app.Notification.Builder setShowWhen(boolean); method @NonNull public android.app.Notification.Builder setSmallIcon(@DrawableRes int); diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 7a36fbb55dc4..81d2c890ee31 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -1281,6 +1281,15 @@ public class Notification implements Parcelable public static final String EXTRA_BIG_TEXT = "android.bigText"; /** + * {@link #extras} key: very short text summarizing the most critical information contained in + * the notification. + * + * @hide + */ + @FlaggedApi(Flags.FLAG_API_RICH_ONGOING) + public static final String EXTRA_SHORT_CRITICAL_TEXT = "android.shortCriticalText"; + + /** * {@link #extras} key: this is the resource ID of the notification's main small icon, as * supplied to {@link Builder#setSmallIcon(int)}. * @@ -4050,6 +4059,17 @@ public class Notification implements Parcelable return String.join("|", defaultStrings); } + + /** + * Returns the very short text summarizing the most critical information contained in the + * notification, or null if this field was not set. + */ + @Nullable + @FlaggedApi(Flags.FLAG_API_RICH_ONGOING) + public String getShortCriticalText() { + return extras.getString(EXTRA_SHORT_CRITICAL_TEXT); + } + /** * @hide */ @@ -4991,6 +5011,18 @@ public class Notification implements Parcelable } /** + * Sets a very short string summarizing the most critical information contained in the + * notification. Suggested max length is 5 characters, and there is no guarantee how much or + * how little of this text will be shown. + */ + @FlaggedApi(Flags.FLAG_API_RICH_ONGOING) + @NonNull + public Builder setShortCriticalText(@Nullable String shortCriticalText) { + mN.extras.putString(EXTRA_SHORT_CRITICAL_TEXT, shortCriticalText); + return this; + } + + /** * Set the progress this notification represents. * * The platform template will represent this using a {@link ProgressBar}. diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java index ef6ff0518dac..0837b458c3ba 100644 --- a/core/tests/coretests/src/android/app/NotificationTest.java +++ b/core/tests/coretests/src/android/app/NotificationTest.java @@ -215,6 +215,25 @@ public class NotificationTest { } @Test + @EnableFlags(Flags.FLAG_API_RICH_ONGOING) + public void testGetShortCriticalText_noneSet() { + Notification n = new Notification.Builder(mContext, "test") + .build(); + + assertSame(n.getShortCriticalText(), null); + } + + @Test + @EnableFlags(Flags.FLAG_API_RICH_ONGOING) + public void testGetShortCriticalText_isSet() { + Notification n = new Notification.Builder(mContext, "test") + .setShortCriticalText("short critical text here") + .build(); + + assertSame(n.getShortCriticalText(), "short critical text here"); + } + + @Test public void largeIconMultipleReferences_keptAfterParcelling() { Icon originalIcon = Icon.createWithBitmap(BitmapFactory.decodeResource( mContext.getResources(), com.android.frameworks.coretests.R.drawable.test128x96)); |