Provides methods for reading and writing basic data types and arrays, inter-process communication (IPC) objects, interface tokens, and sequenceable objects.
Provides APIs for reading and writing data in specific format. During RPC, the sender can use the **write()** method provided **MessageParcel** to write data to a **MessageParcel** object in specific format. The receiver can use the **read()** method provided by **MessageParcel** to read data in specific format from a **MessageParcel** object. The data formats include basic data types and arrays, IPC objects, interface tokens, and custom sequenceable objects.
### create
...
...
@@ -28,7 +28,8 @@ Creates a **MessageParcel** object. This method is a static method.
| token | string | Yes| Interface token to write.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
...
...
@@ -175,12 +181,13 @@ Writes an interface token to this **MessageParcel** object.
readInterfaceToken(): string
Reads the interface token from this **MessageParcel** object. The interface tokens are read in the order in which they are written into the **MessageParcel** object.
Reads the interface token from this **MessageParcel** object. The interface token is read in the sequence in which it is written to the **MessageParcel** object. The local object can use it to verify the communication.
| floatArray | number[] | Yes| FloatArray to write. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
...
...
@@ -1347,7 +1417,8 @@ Reads a FloatArray from this **MessageParcel** object.
| dataIn | number[] | Yes| FloatArray to read. The system processes Float data as that of the Double type. Therefore, the total number of bytes occupied by a FloatArray must be calculated as the Double type.|
...
...
@@ -1372,7 +1443,8 @@ Reads the FloatArray from this **MessageParcel** object.
| [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2521,24 +2639,26 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
### sendRequest<sup>8+(deprecated)</sup>
> **NOTE**<br/>
> This API is deprecated since API Version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9).
> This API is deprecated since API version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9).
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2546,7 +2666,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -2559,7 +2680,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2567,7 +2689,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -2580,7 +2703,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2598,13 +2722,15 @@ Adds a callback for receiving death notifications of the remote object. This met
> This API is deprecated since API version 8. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-1).
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2694,7 +2825,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
...
...
@@ -2741,17 +2873,18 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
### sendRequest<sup>8+(deprecated)</sup>
> **NOTE**<br/>
> This API is deprecated since API Version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-1).
> This API is deprecated since API version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-1).
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2759,7 +2892,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -2818,7 +2952,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2826,7 +2961,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -2885,7 +3021,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -2946,12 +3083,14 @@ Obtains the **LocalInterface** object of an interface descriptor.
| number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
...
...
@@ -3488,7 +3646,8 @@ Changes the UID and PID of the remote user to the UID and PID of the local user.
> This API is deprecated since API version 8. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-2).
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -3581,7 +3744,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
...
...
@@ -3630,17 +3794,18 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
### sendRequest<sup>8+(deprecated)</sup>
> **NOTE**<br/>
> This API is deprecated since API Version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-2).
> This API is deprecated since API version 9. You are advised to use [sendRequestAsync<sup>9+</sup>](#sendrequestasync9-2).
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -3648,7 +3813,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -3709,7 +3875,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -3717,7 +3884,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| Type| Description|
| -------- | -------- |
| Promise<SendRequestResult> | Promise used to return the **sendRequestResult** object.|
...
...
@@ -3777,7 +3945,8 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
...
...
@@ -3831,16 +4000,21 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns a Boolean value if the request is processed synchronously in **onRemoteRequestEx**. If the operation is successful, **true** is returned. Otherwise, **false** is returned.|
| Promise\<boolean> | Returns a promise object if the request is processed asynchronously in **onRemoteRequestEx**.|
**Example**: Overload **onRemoteRequestEx** to process a request synchronously.