Megosztás a következőn keresztül:


IOnReceiveContentListener.OnReceiveContent(View, ContentInfo) Method

Definition

Receive the given content.

[Android.Runtime.Register("onReceiveContent", "(Landroid/view/View;Landroid/view/ContentInfo;)Landroid/view/ContentInfo;", "GetOnReceiveContent_Landroid_view_View_Landroid_view_ContentInfo_Handler:Android.Views.IOnReceiveContentListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)]
public Android.Views.ContentInfo? OnReceiveContent (Android.Views.View view, Android.Views.ContentInfo payload);
[<Android.Runtime.Register("onReceiveContent", "(Landroid/view/View;Landroid/view/ContentInfo;)Landroid/view/ContentInfo;", "GetOnReceiveContent_Landroid_view_View_Landroid_view_ContentInfo_Handler:Android.Views.IOnReceiveContentListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=31)>]
abstract member OnReceiveContent : Android.Views.View * Android.Views.ContentInfo -> Android.Views.ContentInfo

Parameters

view
View

The view where the content insertion was requested.

payload
ContentInfo

The content to insert and related metadata. The payload may contain multiple items and their MIME types may be different (e.g. an image item and a text item). The payload may also contain items whose MIME type is not in the list of MIME types specified when View#setOnReceiveContentListener setting the listener. For those items, the listener may reject the content (defer to the default platform behavior) or execute some other fallback logic (e.g. show an appropriate message to the user).

Returns

The portion of the passed-in content whose processing should be delegated to the platform. Return null if all content was handled in some way. Actual insertion of the content may be processed asynchronously in the background and may or may not succeed even if this method returns null. For example, an app may end up not inserting an item if it exceeds the app's size limit for that type of content.

Attributes

Remarks

Receive the given content.

Implementations should handle any content items of interest and return all unhandled items to preserve the default platform behavior for content that does not have app-specific handling. For example, an implementation may provide handling for content URIs (to provide support for inserting images, etc) and delegate the processing of text to the platform to preserve the common behavior for inserting text. See the class javadoc for a sample implementation.

<h3>Handling different content</h3> <ul> <li>Text. If the ContentInfo#getSource() source is ContentInfo#SOURCE_AUTOFILL autofill, the view's content should be fully replaced by the passed-in text. For sources other than autofill, the passed-in text should overwrite the current selection or be inserted at the current cursor position if there is no selection. <li>Non-text content (e.g. images). The content may be inserted inline if the widget supports this, or it may be added as an attachment (could potentially be shown in a completely separate view). </ul>

<h3>URI permissions</h3>

android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION Read permissions are granted automatically by the platform for any android.content.ContentResolver#SCHEME_CONTENT content URIs in the payload passed to this listener. Permissions are transient and will be released automatically by the platform.

Processing of content should normally be done in a service or activity. For long-running processing, using androidx.work.WorkManager is recommended. When implementing this, permissions should be extended to the target service or activity by passing the content using android.content.Intent#setClipData Intent.setClipData and android.content.Intent#addFlags(int) setting the flag android.content.Intent#FLAG_GRANT_READ_URI_PERMISSION FLAG_GRANT_READ_URI_PERMISSION.

Alternatively, if using a background thread within the current context to process the content, a reference to the payload object should be maintained to ensure that permissions are not revoked prematurely.

Java documentation for android.view.OnReceiveContentListener.onReceiveContent(android.view.View, android.view.ContentInfo).

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