Partager via


View.SetOnReceiveContentListener(String[], IOnReceiveContentListener) Method

Definition

Sets the listener to be #performReceiveContent used to handle insertion of content into this view.

[Android.Runtime.Register("setOnReceiveContentListener", "([Ljava/lang/String;Landroid/view/OnReceiveContentListener;)V", "GetSetOnReceiveContentListener_arrayLjava_lang_String_Landroid_view_OnReceiveContentListener_Handler", ApiSince=31)]
public virtual void SetOnReceiveContentListener (string[]? mimeTypes, Android.Views.IOnReceiveContentListener? listener);
[<Android.Runtime.Register("setOnReceiveContentListener", "([Ljava/lang/String;Landroid/view/OnReceiveContentListener;)V", "GetSetOnReceiveContentListener_arrayLjava_lang_String_Landroid_view_OnReceiveContentListener_Handler", ApiSince=31)>]
abstract member SetOnReceiveContentListener : string[] * Android.Views.IOnReceiveContentListener -> unit
override this.SetOnReceiveContentListener : string[] * Android.Views.IOnReceiveContentListener -> unit

Parameters

mimeTypes
String[]

The MIME types accepted by the given listener. These may use patterns such as "image/*", but may not start with a wildcard. This argument must not be null or empty if a non-null listener is passed in.

listener
IOnReceiveContentListener

The listener to use. This can be null to reset to the default behavior.

Attributes

Remarks

Sets the listener to be #performReceiveContent used to handle insertion of content into this view.

Depending on the type of view, this listener may be invoked for different scenarios. For example, for an editable android.widget.TextView, this listener will be invoked for the following scenarios: <ol> <li>Paste from the clipboard (e.g. "Paste" or "Paste as plain text" action in the insertion/selection menu) <li>Content insertion from the keyboard (from InputConnection#commitContent) <li>Drag and drop (drop events from #onDragEvent) <li>Autofill <li>Selection replacement via Intent#ACTION_PROCESS_TEXT</ol>

When setting a listener, clients must also declare the accepted MIME types. The listener will still be invoked even if the MIME type of the content is not one of the declared MIME types (e.g. if the user pastes content whose type is not one of the declared MIME types). In that case, 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). The declared MIME types serve as a hint to allow different features to optionally alter their behavior. For example, a soft keyboard may optionally choose to hide its UI for inserting GIFs for a particular input field if the MIME types set here for that field don't include "image/gif" or "image/*".

Note: MIME type matching in the Android framework is case-sensitive, unlike formal RFC MIME types. As a result, you should always write your MIME types with lowercase letters, or use android.content.Intent#normalizeMimeType to ensure that it is converted to lowercase.

Java documentation for android.view.View.setOnReceiveContentListener(java.lang.String[], android.view.OnReceiveContentListener).

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