diff --git a/core/api/current.txt b/core/api/current.txt index aeeecf89dd0e2..55f81c5bd21e1 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -8349,6 +8349,7 @@ package android.appwidget { method public android.appwidget.AppWidgetProviderInfo clone(); method public int describeContents(); method public final android.os.UserHandle getProfile(); + method @Nullable public final String loadDescription(@NonNull android.content.Context); method public final android.graphics.drawable.Drawable loadIcon(@NonNull android.content.Context, int); method public final String loadLabel(android.content.pm.PackageManager); method public final android.graphics.drawable.Drawable loadPreviewImage(@NonNull android.content.Context, int); @@ -8366,6 +8367,7 @@ package android.appwidget { field public static final int WIDGET_FEATURE_RECONFIGURABLE = 1; // 0x1 field public int autoAdvanceViewId; field public android.content.ComponentName configure; + field @IdRes public int descriptionResource; field public int icon; field public int initialKeyguardLayout; field public int initialLayout; diff --git a/core/java/android/appwidget/AppWidgetProviderInfo.java b/core/java/android/appwidget/AppWidgetProviderInfo.java index 062076bb15ef3..93d96d074db8b 100644 --- a/core/java/android/appwidget/AppWidgetProviderInfo.java +++ b/core/java/android/appwidget/AppWidgetProviderInfo.java @@ -16,8 +16,11 @@ package android.appwidget; +import android.annotation.IdRes; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SuppressLint; import android.app.PendingIntent; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; @@ -272,6 +275,15 @@ public class AppWidgetProviderInfo implements Parcelable { @CategoryFlags public int widgetCategory; + /** + * Resource id for the description of the AppWidget. + *
This field corresponds to the android:description attribute in the AppWidget
+ * meta-data file.
+ */
+ @SuppressLint("MutableBareField")
+ @IdRes
+ public int descriptionResource;
+
/**
* Flags indicating various features supported by the widget. These are hints to the widget
* host, and do not actually change the behavior of the widget.
@@ -313,6 +325,7 @@ public class AppWidgetProviderInfo implements Parcelable {
this.widgetCategory = in.readInt();
this.providerInfo = in.readTypedObject(ActivityInfo.CREATOR);
this.widgetFeatures = in.readInt();
+ this.descriptionResource = in.readInt();
}
/**
@@ -369,6 +382,21 @@ public class AppWidgetProviderInfo implements Parcelable {
return loadDrawable(context, density, previewImage, false);
}
+ /** Loads localized description for the app widget. */
+ @Nullable
+ public final String loadDescription(@NonNull Context context) {
+ if (ResourceId.isValid(descriptionResource)) {
+ return context.getPackageManager()
+ .getText(
+ providerInfo.packageName,
+ descriptionResource,
+ providerInfo.applicationInfo)
+ .toString()
+ .trim();
+ }
+ return null;
+ }
+
/**
* Gets the user profile in which the provider resides.
*
@@ -398,6 +426,7 @@ public class AppWidgetProviderInfo implements Parcelable {
out.writeInt(this.widgetCategory);
out.writeTypedObject(this.providerInfo, flags);
out.writeInt(this.widgetFeatures);
+ out.writeInt(this.descriptionResource);
}
@Override
@@ -421,6 +450,7 @@ public class AppWidgetProviderInfo implements Parcelable {
that.widgetCategory = this.widgetCategory;
that.providerInfo = this.providerInfo;
that.widgetFeatures = this.widgetFeatures;
+ that.descriptionResource = this.descriptionResource;
return that;
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 453beaf0de354..243c2448a3b10 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -7997,6 +7997,8 @@
the provided configuration activity. -->