Item
open class Item
| kotlin.Any | |
| ↳ | android.content.ClipData.Item |
Description of a single item in a ClipData.
The types than an individual item can currently contain are:
- Text: a basic string of text. This is actually a CharSequence, so it can be formatted text supported by corresponding Android built-in style spans. (Custom application spans are not supported and will be stripped when transporting through the clipboard.)
- Intent: an arbitrary Intent object. A typical use is the shortcut to create when pasting a clipped item on to the home screen.
- Uri: a URI reference. This may be any URI (such as an http: URI representing a bookmark), however it is often a content: URI. Using content provider references as clips like this allows an application to share complex or large clips through the standard content provider facilities.
Summary
Public constructors |
|
|---|---|
<init>(text: CharSequence!)Create an Item consisting of a single block of (possibly styled) text. |
|
<init>(text: CharSequence!, htmlText: String!)Create an Item consisting of a single block of (possibly styled) text, with an alternative HTML formatted representation. |
|
|
Create an Item consisting of an arbitrary Intent. |
|
|
Create an Item consisting of an arbitrary URI. |
|
<init>(text: CharSequence!, intent: Intent!, uri: Uri!)Create a complex Item, containing multiple representations of text, Intent, and/or URI. |
|
<init>(text: CharSequence!, htmlText: String!, intent: Intent!, uri: Uri!)Create a complex Item, containing multiple representations of text, HTML text, Intent, and/or URI. |
|
Public methods |
|
|---|---|
| open String! |
coerceToHtmlText(context: Context!)Turn this item into HTML text, regardless of the type of data it actually contains. |
| open CharSequence! |
coerceToStyledText(context: Context!)Like |
| open CharSequence! |
coerceToText(context: Context!)Turn this item into text, regardless of the type of data it actually contains. |
| open String! |
Retrieve the raw HTML text contained in this Item. |
| open Intent! |
Retrieve the raw Intent contained in this Item. |
| open CharSequence! |
getText()Retrieve the raw text contained in this Item. |
| open Uri! |
getUri()Retrieve the raw URI contained in this Item. |
| open String |
toString() |
Public constructors
<init>
Item(text: CharSequence!)
Create an Item consisting of a single block of (possibly styled) text.
<init>
Item(
text: CharSequence!,
htmlText: String!)
Create an Item consisting of a single block of (possibly styled) text, with an alternative HTML formatted representation. You must supply a plain text representation in addition to HTML text; coercion will not be done from HTML formatted text into plain text.
Note: It is strongly recommended to use content: URI for sharing large clip data. Starting on API 30, ClipData.Item doesn't accept an HTML text if it's larger than 800KB.
<init>
Item(intent: Intent!)
Create an Item consisting of an arbitrary Intent.
<init>
Item(
text: CharSequence!,
intent: Intent!,
uri: Uri!)
Create a complex Item, containing multiple representations of text, Intent, and/or URI.
<init>
Item(
text: CharSequence!,
htmlText: String!,
intent: Intent!,
uri: Uri!)
Create a complex Item, containing multiple representations of text, HTML text, Intent, and/or URI. If providing HTML text, you must supply a plain text representation as well; coercion will not be done from HTML formatted text into plain text.
Public methods
coerceToHtmlText
open fun coerceToHtmlText(context: Context!): String!
Turn this item into HTML text, regardless of the type of data it actually contains.
The algorithm for deciding what text to return is:
- If
getHtmlTextis non-null, return that. - If
getTextis non-null, return that, converting to valid HTML text. If this text contains style spans,Html#toHtml(Spanned)is used to convert them to HTML formatting. - If
getUriis non-null, try to retrieve its data as a text stream from its content provider. If the provider can supply text/html data, that will be preferred and returned as-is. Otherwise, any text/* data will be returned and escaped to HTML. If it is not a content: URI or the content provider does not supply a text representation, HTML text containing a link to the URI will be returned. - If
getIntentis non-null, convert that to an intent: URI and return as an HTML link. - Otherwise, return an empty string.
| Parameters | |
|---|---|
context |
Context!: The caller's Context, from which its ContentResolver and other things can be retrieved. |
| Return | |
|---|---|
String! |
Returns the item's representation as HTML text. |
coerceToStyledText
open fun coerceToStyledText(context: Context!): CharSequence!
Like coerceToHtmlText(android.content.Context), but any text that would be returned as HTML formatting will be returned as text with style spans.
| Parameters | |
|---|---|
context |
Context!: The caller's Context, from which its ContentResolver and other things can be retrieved. |
| Return | |
|---|---|
CharSequence! |
Returns the item's textual representation. |
coerceToText
open fun coerceToText(context: Context!): CharSequence!
Turn this item into text, regardless of the type of data it actually contains.
The algorithm for deciding what text to return is:
- If
getTextis non-null, return that. - If
getUriis non-null, try to retrieve its data as a text stream from its content provider. If this succeeds, copy the text into a String and return it. If it is not a content: URI or the content provider does not supply a text representation, return the raw URI as a string. - If
getIntentis non-null, convert that to an intent: URI and return it. - Otherwise, return an empty string.
| Parameters | |
|---|---|
context |
Context!: The caller's Context, from which its ContentResolver and other things can be retrieved. |
| Return | |
|---|---|
CharSequence! |
Returns the item's textual representation. |
getHtmlText
open fun getHtmlText(): String!
Retrieve the raw HTML text contained in this Item.
getIntent
open fun getIntent(): Intent!
Retrieve the raw Intent contained in this Item.
getText
open fun getText(): CharSequence!
Retrieve the raw text contained in this Item.
toString
open fun toString(): String
| Return | |
|---|---|
String |
a string representation of the object. |