WebResourceResponse
open class WebResourceResponse
kotlin.Any | |
↳ | android.webkit.WebResourceResponse |
Encapsulates a resource response. Applications can return an instance of this class from android.webkit.WebViewClient#shouldInterceptRequest to provide a custom response when the WebView requests a particular resource.
Summary
Public constructors | |
---|---|
WebResourceResponse(mimeType: String!, encoding: String!, statusCode: Int, reasonPhrase: String, responseHeaders: MutableMap<String!, String!>!, data: InputStream!) Constructs a resource response with the given parameters. |
|
WebResourceResponse(mimeType: String!, encoding: String!, data: InputStream!) Constructs a resource response with the given MIME type, character encoding, and input stream. |
Public methods | |
---|---|
open InputStream! |
getData() Gets the input stream that provides the resource response's data. |
open String! |
Gets the resource response's encoding. |
open String! |
Gets the resource response's MIME type. |
open String! |
Gets the description of the resource response's status code. |
open MutableMap<String!, String!>! |
Gets the headers for the resource response. |
open Int |
Gets the resource response's status code. |
open Unit |
setData(data: InputStream!) Sets the input stream that provides the resource response's data. |
open Unit |
setEncoding(encoding: String!) Sets the resource response's encoding, for example "UTF-8". |
open Unit |
setMimeType(mimeType: String!) Sets the resource response's MIME type, for example "text/html". |
open Unit |
setResponseHeaders(headers: MutableMap<String!, String!>!) Sets the headers for the resource response. |
open Unit |
setStatusCodeAndReasonPhrase(statusCode: Int, reasonPhrase: String) Sets the resource response's status code and reason phrase. |
Public constructors
WebResourceResponse
WebResourceResponse(
mimeType: String!,
encoding: String!,
statusCode: Int,
reasonPhrase: String,
responseHeaders: MutableMap<String!, String!>!,
data: InputStream!)
Constructs a resource response with the given parameters. Callers must implement InputStream.read(byte[])
for the input stream. java.io.InputStream#close() will be called after the WebView has finished with the response.
Note: See WebResourceResponse(java.lang.String,java.lang.String,java.io.InputStream)
for details on what should be specified for mimeType
and encoding
.
Parameters | |
---|---|
mimeType |
String!: the resource response's MIME type, for example "text/html" . |
encoding |
String!: the resource response's character encoding, for example "utf-8" . |
statusCode |
Int: the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported. |
reasonPhrase |
String: the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be null . |
responseHeaders |
MutableMap<String!, String!>!: the resource response's headers represented as a mapping of header name -> header value. |
data |
InputStream!: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
WebResourceResponse
WebResourceResponse(
mimeType: String!,
encoding: String!,
data: InputStream!)
Constructs a resource response with the given MIME type, character encoding, and input stream. Callers must implement InputStream.read(byte[])
for the input stream. java.io.InputStream#close() will be called after the WebView has finished with the response.
Note: The MIME type and character encoding must be specified as separate parameters (for example "text/html"
and "utf-8"
), not a single value like the "text/html; charset=utf-8"
format used in the HTTP Content-Type header. Do not use the value of a HTTP Content-Encoding header for encoding
, as that header does not specify a character encoding. Content without a defined character encoding (for example image resources) should pass null
for encoding
.
Parameters | |
---|---|
mimeType |
String!: the resource response's MIME type, for example "text/html" . |
encoding |
String!: the resource response's character encoding, for example "utf-8" . |
data |
InputStream!: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
Public methods
getData
open fun getData(): InputStream!
Gets the input stream that provides the resource response's data.
Return | |
---|---|
InputStream! |
The input stream that provides the resource response's data |
getEncoding
open fun getEncoding(): String!
Gets the resource response's encoding.
Return | |
---|---|
String! |
The resource response's encoding |
getMimeType
open fun getMimeType(): String!
Gets the resource response's MIME type.
Return | |
---|---|
String! |
The resource response's MIME type |
getReasonPhrase
open fun getReasonPhrase(): String!
Gets the description of the resource response's status code.
Return | |
---|---|
String! |
The description of the resource response's status code. |
getResponseHeaders
open fun getResponseHeaders(): MutableMap<String!, String!>!
Gets the headers for the resource response.
Return | |
---|---|
MutableMap<String!, String!>! |
The headers for the resource response. |
getStatusCode
open fun getStatusCode(): Int
Gets the resource response's status code.
Return | |
---|---|
Int |
The resource response's status code. |
setData
open fun setData(data: InputStream!): Unit
Sets the input stream that provides the resource response's data. Callers must implement InputStream.read(byte[])
. java.io.InputStream#close() will be called after the WebView has finished with the response.
Parameters | |
---|---|
data |
InputStream!: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
setEncoding
open fun setEncoding(encoding: String!): Unit
Sets the resource response's encoding, for example "UTF-8". This is used to decode the data from the input stream.
Parameters | |
---|---|
encoding |
String!: The resource response's encoding |
setMimeType
open fun setMimeType(mimeType: String!): Unit
Sets the resource response's MIME type, for example "text/html".
Parameters | |
---|---|
mimeType |
String!: The resource response's MIME type |
setResponseHeaders
open fun setResponseHeaders(headers: MutableMap<String!, String!>!): Unit
Sets the headers for the resource response.
Parameters | |
---|---|
headers |
MutableMap<String!, String!>!: Mapping of header name -> header value. |
setStatusCodeAndReasonPhrase
open fun setStatusCodeAndReasonPhrase(
statusCode: Int,
reasonPhrase: String
): Unit
Sets the resource response's status code and reason phrase.
Parameters | |
---|---|
statusCode |
Int: the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported. |
reasonPhrase |
String: the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be null . |