Compartir a través de


AppWidgetManager.RequestPinAppWidget Method

Definition

Request to pin an app widget on the current launcher.

[Android.Runtime.Register("requestPinAppWidget", "(Landroid/content/ComponentName;Landroid/os/Bundle;Landroid/app/PendingIntent;)Z", "GetRequestPinAppWidget_Landroid_content_ComponentName_Landroid_os_Bundle_Landroid_app_PendingIntent_Handler", ApiSince=26)]
public virtual bool RequestPinAppWidget (Android.Content.ComponentName provider, Android.OS.Bundle? extras, Android.App.PendingIntent? successCallback);
[<Android.Runtime.Register("requestPinAppWidget", "(Landroid/content/ComponentName;Landroid/os/Bundle;Landroid/app/PendingIntent;)Z", "GetRequestPinAppWidget_Landroid_content_ComponentName_Landroid_os_Bundle_Landroid_app_PendingIntent_Handler", ApiSince=26)>]
abstract member RequestPinAppWidget : Android.Content.ComponentName * Android.OS.Bundle * Android.App.PendingIntent -> bool
override this.RequestPinAppWidget : Android.Content.ComponentName * Android.OS.Bundle * Android.App.PendingIntent -> bool

Parameters

provider
ComponentName

The ComponentName for the android.content.BroadcastReceiver BroadcastReceiver provider for your AppWidget.

extras
Bundle

In not null, this is passed to the launcher app. For eg #EXTRA_APPWIDGET_PREVIEW can be used for a custom preview.

successCallback
PendingIntent

If not null, this intent will be sent when the widget is created.

Returns

TRUE if the launcher supports this feature. Note the API will return without waiting for the user to respond, so getting TRUE from this API does not mean the shortcut is pinned. FALSE if the launcher doesn't support this feature.

Attributes

Remarks

Request to pin an app widget on the current launcher. It's up to the launcher to accept this request (optionally showing a user confirmation). If the request is accepted, the caller will get a confirmation with extra #EXTRA_APPWIDGET_ID.

When a request is denied by the user, the caller app will not get any response.

Only apps with a foreground activity or a foreground service can call it. Otherwise it'll throw IllegalStateException.

It's up to the launcher how to handle previous pending requests when the same package calls this API multiple times in a row. It may ignore the previous requests, for example.

Launcher will not show the configuration activity associated with the provider in this case. The app could either show the configuration activity as a response to the callback, or show if before calling the API (various configurations can be encapsulated in successCallback to avoid persisting them before the widgetId is known).

Java documentation for android.appwidget.AppWidgetManager.requestPinAppWidget(android.content.ComponentName, android.os.Bundle, android.app.PendingIntent).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to