1# @ohos.cooperate (Screen Hopping) (System API)
2
3The **cooperate** module implements screen hopping for two or more networked devices to share the keyboard and mouse for collaborative operations.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9> - The APIs provided by this module are system APIs.
10
11## Modules to Import
12
13```ts
14import cooperate from '@ohos.cooperate';
15```
16
17## cooperate.prepareCooperate<sup>11+</sup>
18
19prepareCooperate(callback: AsyncCallback&lt;void&gt;): void;
20
21Prepares for screen hopping. This API uses an asynchronous callback to return the result.
22
23**Required permissions**: ohos.permission.COOPERATE_MANAGER
24
25**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
26
27**Parameters**
28
29| Name  | Type                     | Mandatory| Description                                                        |
30| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
31| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
32
33**Error codes**
34
35For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
36
37| ID| Error Message         |
38| -------- | ----------------- |
39| 201 | Permission denied. |
40| 202 | Not system application. |
41| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
42
43**Example**
44
45```ts
46import { BusinessError } from '@ohos.base';
47try {
48  cooperate.prepareCooperate((error: BusinessError) => {
49    if (error) {
50      console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
51      return;
52    }
53    console.log(`Keyboard mouse crossing prepareCooperate success.`);
54  });
55} catch (error) {
56  console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
57}
58```
59
60## cooperate.prepareCooperate<sup>11+</sup>
61
62prepareCooperate(): Promise&lt;void&gt;;
63
64Prepares for screen hopping. This API uses a promise to return the result.
65
66**Required permissions**: ohos.permission.COOPERATE_MANAGER
67
68**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
69
70**Return value**
71
72| Parameters               | Description                     |
73| ------------------- | ------------------------- |
74| Promise&lt;void&gt; | Promise that returns no value.|
75
76**Error codes**
77
78For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
79
80| ID| Error Message         |
81| -------- | ----------------- |
82| 201 | Permission denied. |
83| 202 | Not system application. |
84| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
85
86**Example**
87
88```ts
89import { BusinessError } from '@ohos.base';
90try {
91  cooperate.prepareCooperate().then(() => {
92    console.log(`Keyboard mouse crossing prepareCooperate success.`);
93  }, (error: BusinessError) => {
94    console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
95  });
96} catch (error) {
97  console.log(`Keyboard mouse crossing prepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
98}
99```
100
101
102
103## cooperate.unprepareCooperate<sup>11+</sup>
104
105unprepareCooperate(callback: AsyncCallback&lt;void&gt;): void;
106
107Cancels the preparation for screen hopping. This API uses an asynchronous callback to return the result.
108
109**Required permissions**: ohos.permission.COOPERATE_MANAGER
110
111**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
112
113| Name  | Type                     | Mandatory| Description                                                        |
114| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
115| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
116
117**Error codes**
118
119For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
120
121| ID| Error Message         |
122| -------- | ----------------- |
123| 201 | Permission denied. |
124| 202 | Not system application. |
125| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
126
127**Example**
128
129```ts
130import { BusinessError } from '@ohos.base';
131try {
132  cooperate.unprepareCooperate((error: BusinessError) => {
133    if (error) {
134      console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
135      return;
136    }
137    console.log(`Keyboard mouse crossing unprepareCooperate success.`);
138  });
139} catch (error) {
140  console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
141}
142```
143
144## cooperate.unprepareCooperate<sup>11+</sup>
145
146unprepareCooperate(): Promise&lt;void&gt;;
147
148Cancels the preparation for screen hopping. This API uses a promise to return the result.
149
150**Required permissions**: ohos.permission.COOPERATE_MANAGER
151
152**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
153
154**Return value**
155
156| Parameters               | Description                     |
157| ------------------- | ------------------------- |
158| Promise&lt;void&gt; | Promise that returns no value.|
159
160**Error codes**
161
162For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
163
164| ID| Error Message         |
165| -------- | ----------------- |
166| 201 | Permission denied. |
167| 202 | Not system application. |
168
169**Example**
170
171```ts
172import { BusinessError } from '@ohos.base';
173try {
174  cooperate.unprepareCooperate().then(() => {
175    console.log(`Keyboard mouse crossing unprepareCooperate success.`);
176  }, (error: BusinessError) => {
177    console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
178  });
179} catch (error) {
180  console.log(`Keyboard mouse crossing unprepareCooperate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
181}
182```
183
184
185
186## cooperate.activateCooperate<sup>11+</sup>
187
188activateCooperate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback&lt;void&gt;): void;
189
190Starts screen hopping. This API uses an asynchronous callback to return the result.
191
192**Required permissions**: ohos.permission.COOPERATE_MANAGER
193
194**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
195
196**Parameters**
197
198| Name         | Type                     | Mandatory| Description                                                        |
199| --------------- | ------------------------- | ---- | ------------------------------------------------------------ |
200| targetNetworkId | string                    | Yes  | Descriptor of the target device for screen hopping.                                    |
201| inputDeviceId   | number                    | Yes  | Identifier of the input device for screen hopping.                                      |
202| callback        | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
203
204**Error codes**
205
206For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
207
208| ID| Error Message         |
209| -------- | ----------------- |
210| 201 | Permission denied. |
211| 202 | Not system application. |
212| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
213| 20900001 | Operation failed. |
214
215**Example**
216
217```ts
218import { BusinessError } from '@ohos.base';
219let targetNetworkId = "networkId";
220let inputDeviceId = 0;
221try {
222  cooperate.activateCooperate(targetNetworkId, inputDeviceId, (error: BusinessError) => {
223    if (error) {
224      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
225      return;
226    }
227    console.log(`Start Keyboard mouse crossing success.`);
228  });
229} catch (error) {
230  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
231}
232```
233
234## cooperate.activateCooperate<sup>11+</sup>
235
236activateCooperate(targetNetworkId: string, inputDeviceId: number): Promise&lt;void&gt;;
237
238Starts screen hopping. This API uses a promise to return the result.
239
240**Required permissions**: ohos.permission.COOPERATE_MANAGER
241
242**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
243
244**Parameters**
245
246| Name         | Type  | Mandatory| Description                    |
247| --------------- | ------ | ---- | ------------------------ |
248| targetNetworkId | string | Yes  | Descriptor of the target device for screen hopping.|
249| inputDeviceId   | number | Yes  | Identifier of the input device for screen hopping.  |
250
251**Return value**
252
253| Name             | Description                     |
254| ------------------- | ------------------------- |
255| Promise&lt;void&gt; | Promise that returns no value.|
256
257**Error codes**
258
259For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
260
261| ID| Error Message         |
262| -------- | ----------------- |
263| 201 | Permission denied. |
264| 202 | Not system application. |
265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
266| 20900001 | Operation failed. |
267
268**Example**
269
270```ts
271import { BusinessError } from '@ohos.base';
272let targetNetworkId = "networkId";
273let inputDeviceId = 0;
274try {
275 cooperate.activateCooperate(targetNetworkId, inputDeviceId).then(() => {
276    console.log(`Start Keyboard mouse crossing success.`);
277  }, (error: BusinessError) => {
278    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
279  });
280} catch (error) {
281  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
282}
283```
284
285
286
287## cooperate.deactivateCooperate<sup>11+</sup>
288
289deactivateCooperate(isUnchained: boolean, callback: AsyncCallback&lt;void&gt;): void;
290
291Stops screen hopping. This API uses an asynchronous callback to return the result.
292
293**Required permissions**: ohos.permission.COOPERATE_MANAGER
294
295**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
296
297**Parameters**
298
299| Name     | Type                     | Mandatory| Description                                                        |
300| ----------- | ------------------------- | ---- | ------------------------------------------------------------ |
301| isUnchained | boolean                   | Yes  | Whether to disable the cross-device link. The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
302| callback    | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
303
304**Error codes**
305
306For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
307
308| ID| Error Message         |
309| -------- | ----------------- |
310| 201 | Permission denied. |
311| 202 | Not system application. |
312| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
313
314**Example**
315
316```ts
317import { BusinessError } from '@ohos.base';
318try {
319  cooperate.deactivateCooperate(false, (error: BusinessError) => {
320    if (error) {
321      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
322      return;
323    }
324    console.log(`Stop Keyboard mouse crossing success.`);
325  });
326} catch (error) {
327  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
328}
329```
330
331## cooperate.deactivateCooperate<sup>11+</sup>
332
333deactivateCooperate(isUnchained: boolean): Promise&lt;void&gt;;
334
335Stops screen hopping. This API uses a promise to return the result.
336
337**Required permissions**: ohos.permission.COOPERATE_MANAGER
338
339**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
340
341**Parameters**
342
343| Name     | Type   | Mandatory| Description                                                        |
344| ----------- | ------- | ---- | ------------------------------------------------------------ |
345| isUnchained | boolean | Yes  | Whether to disable the cross-device link. The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
346
347**Return value**
348
349| Name             | Description                     |
350| ------------------- | ------------------------- |
351| Promise&lt;void&gt; | Promise that returns no value.|
352
353**Error codes**
354
355For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
356
357| ID| Error Message         |
358| -------- | ----------------- |
359| 201 | Permission denied. |
360| 202 | Not system application. |
361
362**Example**
363
364```ts
365import { BusinessError } from '@ohos.base';
366try {
367  cooperate.deactivateCooperate(false).then(() => {
368    console.log(`Stop Keyboard mouse crossing success.`);
369  }, (error: BusinessError) => {
370    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
371  });
372} catch (error) {
373  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
374}
375```
376
377
378
379## cooperate.getCooperateSwitchState<sup>11+</sup>
380
381getCooperateSwitchState(networkId: string, callback: AsyncCallback&lt;boolean&gt;): void;
382
383Obtains the screen hopping status of the target device. This API uses an asynchronous callback to return the result.
384
385**Required permissions**: ohos.permission.COOPERATE_MANAGER
386
387**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
388
389**Parameters**
390
391| Name   | Type                        | Mandatory| Description                                                        |
392| --------- | ---------------------------- | ---- | ------------------------------------------------------------ |
393| networkId | string                       | Yes  | Descriptor of the target device for screen hopping.                                    |
394| callback  | AsyncCallback&lt;boolean&gt; | Yes  | Callback used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
395
396**Error codes**
397
398For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
399
400| ID| Error Message         |
401| -------- | ----------------- |
402| 201 | Permission denied. |
403| 202 | Not system application. |
404| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
405
406**Example**
407
408```ts
409import { BusinessError } from '@ohos.base';
410let deviceDescriptor = "networkId";
411try {
412  cooperate.getCooperateSwitchState(deviceDescriptor, (error: BusinessError, data: boolean) => {
413    if (error) {
414      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
415      return;
416    }
417    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
418  });
419} catch (error) {
420  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
421}
422```
423
424## cooperate.getCooperateSwitchState<sup>11+</sup>
425
426getCooperateSwitchState(networkId: string): Promise&lt;boolean&gt;;
427
428Obtains the screen hopping status of the target device. This API uses a promise to return the result.
429
430**Required permissions**: ohos.permission.COOPERATE_MANAGER
431
432**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
433
434**Parameters**
435
436| Name   | Type  | Mandatory| Description                    |
437| --------- | ------ | ---- | ------------------------ |
438| networkId | string | Yes  | Descriptor of the target device for screen hopping.|
439
440**Return value**
441
442| Parameters                  | Description                                                        |
443| ---------------------- | ------------------------------------------------------------ |
444| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
445
446**Error codes**
447
448For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
449
450| ID| Error Message         |
451| -------- | ----------------- |
452| 201 | Permission denied. |
453| 202 | Not system application. |
454| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
455
456**Example**
457
458```ts
459import { BusinessError } from '@ohos.base';
460let deviceDescriptor = "networkId";
461try {
462  cooperate.getCooperateSwitchState(deviceDescriptor).then((data: boolean) => {
463    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
464  }, (error: BusinessError) => {
465    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
466  });
467} catch (error) {
468  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
469}
470```
471
472
473
474## on('cooperateMessage')<sup>11+</sup>
475
476on(type: 'cooperateMessage', callback: Callback&lt;CooperateMessage&gt;): void;
477
478Enables listening for screen hopping status change events.
479
480**Required permissions**: ohos.permission.COOPERATE_MANAGER
481
482**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
483
484**Parameters**
485
486| Name  | Type                                                 | Mandatory| Description                                |
487| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
488| type     | string                                                | Yes  | Event type. The value is **cooperateMessage**.  |
489| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | Yes  | Callback used to return the result.|
490
491**Error codes**
492
493For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
494
495| ID| Error Message         |
496| -------- | ----------------- |
497| 201 | Permission denied. |
498| 202 | Not system application. |
499| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
500
501**Example**
502
503```ts
504function callback(msg: cooperate.CooperateMessage) {
505  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
506  return false;
507}
508try {
509  cooperate.on('cooperateMessage', callback);
510} catch (error) {
511  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
512}
513```
514
515
516
517## off('cooperateMessage')<sup>11+</sup>
518
519off(type: 'cooperateMessage', callback?: Callback&lt;CooperateMessage&gt;): void;
520
521Disables listening for screen hopping status change events.
522
523**Required permissions**: ohos.permission.COOPERATE_MANAGER
524
525**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
526
527**Parameters**
528
529| Name  | Type                                                 | Mandatory| Description                                                        |
530| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
531| type     | string                                                | Yes  | Event type. The value is **cooperate**.                               |
532| callback | Callback&lt;[CooperateMessage](#cooperatemessage11)&gt; | No  | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
533
534**Error codes**
535
536For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
537
538| ID| Error Message         |
539| -------- | ----------------- |
540| 201 | Permission denied. |
541| 202 | Not system application. |
542| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
543
544**Example**
545
546```ts
547// Unregister a single callback.
548function callbackOn(msgOn: cooperate.CooperateMessage) {
549  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msgOn)}`);
550  return false;
551}
552function callbackOff(msgOff: cooperate.CooperateMessage) {
553  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msgOff)}`);
554  return false;
555}
556try {
557  cooperate.on('cooperateMessage', callbackOn);
558  cooperate.off('cooperateMessage', callbackOff);
559} catch (error) {
560  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
561}
562```
563
564```ts
565// Unregister all callbacks.
566function callbackOn(msg: cooperate.CooperateMessage) {
567  console.log(`Keyboard mouse crossing event: ${JSON.stringify(msg)}`);
568  return false;
569}
570try {
571  cooperate.on('cooperateMessage', callbackOn);
572  cooperate.off('cooperateMessage');
573} catch (error) {
574  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
575}
576```
577
578
579## on('cooperateMouse')<sup>12+</sup>
580
581on(type: 'cooperateMouse', networkId: string, callback: Callback&lt;MouseLocation&gt;): void;
582
583Registers a listener for the mouse cursor position of a device.
584
585**Required permissions**: ohos.permission.COOPERATE_MANAGER
586
587**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
588
589**Parameters**
590
591| Name  | Type                                                 | Mandatory| Description                                |
592| -------- | ----------------------------------------------------- | ---- | ------------------------------------ |
593| type     | string                                                | Yes  | Event type, which is **'cooperateMouse'**.  |
594| networkId| string                                                | Yes  | Descriptor of the target device.  |
595| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | Yes  | Callback used to return the mouse cursor position of the device.|
596
597**Error codes**
598
599For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
600
601| ID| Error Message         |
602| -------- | ----------------- |
603| 201 | Permission denied. |
604| 202 | Not system application. |
605| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
606
607**Example**
608
609```ts
610function callback(data: cooperate.MouseLocation) {
611  console.log('displayX:' + data.displayX + 'displayY:' + data.displayX + 'displayWidth:' +
612    data.displayWidth + 'displayHeight:' + data.displayHeight );
613}
614try {
615  let networkId: string = 'Default';
616  cooperate.on('cooperateMouse', networkId, callback);
617} catch (error) {
618  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
619}
620```
621
622
623
624## off('cooperateMouse')<sup>12+</sup>
625
626off(type: 'cooperateMouse', networkId: string, callback?: Callback&lt;MouseLocation&gt;): void;
627
628Unregisters the listener for the mouse cursor position of a device.
629
630**Required permissions**: ohos.permission.COOPERATE_MANAGER
631
632**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
633
634**Parameters**
635
636| Name  | Type                                                 | Mandatory| Description                                                        |
637| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
638| type     | string                                                | Yes  | Event type, which is **'cooperateMouse'**.                               |
639| networkId| string                                                | Yes  | Descriptor of the target device.  |
640| callback | Callback&lt;[MouseLocation](#mouselocation12)&gt; | No  | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
641
642**Error codes**
643
644For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
645
646| ID| Error Message         |
647| -------- | ----------------- |
648| 201 | Permission denied. |
649| 202 | Not system application. |
650| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
651
652**Example**
653
654```ts
655// Unregister a single callback.
656function callbackOn(data: cooperate.MouseLocation) {
657  console.log('Register mouse location listener');
658  return false;
659}
660function callbackOff(data: cooperate.MouseLocation) {
661  console.log('Unregister mouse location listener');
662  return false;
663}
664try {
665  let networkId: string = 'Default';
666  cooperate.on('cooperateMouse', networkId, callbackOn);
667  cooperate.off('cooperateMouse', networkId, callbackOff);
668} catch (error) {
669  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
670}
671```
672
673```ts
674// Unregister all callbacks.
675function callbackOn(data: cooperate.MouseLocation) {
676  console.log('Register mouse location listener');
677}
678try {
679  let networkId: string = 'Default';
680  cooperate.on('cooperateMouse', networkId, callbackOn);
681  cooperate.off('cooperateMouse', networkId);
682} catch (error) {
683  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
684}
685```
686
687
688
689## CooperateMessage<sup>11+</sup>
690
691Defines a screen hopping status change event.
692
693**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
694
695| Name     | Type          | Readable| Writable| Description                    |
696| --------- | -------------- | ---- | ---- | ------------------------ |
697| networkId | string         | Yes  | No  | Descriptor of the target device for screen hopping.|
698| state     | CooperateState | Yes  | No  | Screen hopping status.        |
699
700
701## MouseLocation<sup>12+</sup>
702
703Defines the mouse pointer position for screen hopping.
704
705**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
706
707| Name          | Type           | Readable| Writable| Description                          |
708| ---------      | -------------- | ---- | ---- | ------------------------       |
709| displayX       | number         | Yes  | No  | Position of the mouse pointer on the X coordinate of the screen.|
710| displayY       | number         | Yes  | No  | Position of the mouse pointer on the Y coordinate of the screen.|
711| displayWidth   | number         | Yes  | No  | Screen width.                     |
712| displayHeight  | number         | Yes  | No  | Screen height.                     |
713
714
715
716## CooperateState<sup>11+</sup>
717
718Screen hopping status.
719
720**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
721
722| Name                          | Type   | Readable| Writable| Description                  |
723| ------------------------------ | ------ | ---- | ---- | ---------------------- |
724| COOPERATE_PREPARE              | number | Yes  | No  | The preparation for screen hopping is finished.    |
725| COOPERATE_UNPREPARE            | number | Yes  | No  | The preparation for screen hopping is cancelled.|
726| COOPERATE_ACTIVATE             | number | Yes  | No  | Screen hopping starts.    |
727| COOPERATE_ACTIVATE_SUCCESS     | number | Yes  | No  | Starting screen hopping succeeds.|
728| COOPERATE_ACTIVATE_FAIL        | number | Yes  | No  | Starting screen hopping fails.|
729| COOPERATE_DEACTIVATE_SUCCESS   | number | Yes  | No  | Stopping screen hopping succeeds.|
730| COOPERATE_DEACTIVATE_FAIL      | number | Yes  | No  | Stopping screen hopping fails.|
731| COOPERATE_SESSION_DISCONNECTED | number | Yes  | No  | The screen hopping session is disconnected.|
732| COOPERATE_ACTIVATE_FAILURE     | number | Yes  | No  | Screen hopping fails to start.|
733| COOPERATE_DEACTIVATE_FAILURE   | number | Yes  | No  | Screen hopping fails to stop.|
734
735
736## MouseLocation<sup>12+</sup>
737
738Represents the mouse cursor position.
739
740**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
741
742| Name          | Type          | Readable| Writable| Description                    |
743| ---------     | -------------- | ---- | ---- | ------------------------ |
744| displayX      | number         | Yes  | No  | X coordinate of the mouse cursor.|
745| displayY      | number         | Yes  | No  | Y coordinate of the mouse cursor.|
746| displayWidth  | number         | Yes  | No  | Width of the screen where the mouse cursor is located.|
747| displayHeight | number         | Yes  | No  | Height of the screen where the mouse cursor is located.|
748
749
750## cooperate.prepare<sup>(deprecated)</sup>
751
752prepare(callback: AsyncCallback&lt;void&gt;): void;
753
754Prepares for screen hopping. This API uses an asynchronous callback to return the result.
755
756> **NOTE**
757>
758> This API is deprecated since API version 10. You are advised to use [cooperate.prepareCooperate](#cooperatepreparecooperate11).
759
760**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
761
762**Parameters**
763
764| Name   | Type     | Mandatory | Description   |
765| -------- | ------------------------- | ---- | --------------------------- |
766| callback | AsyncCallback&lt;void&gt;  | Yes|Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.  |
767
768**Error codes**
769
770For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
771
772| ID| Error Message         |
773| -------- | ----------------- |
774| 202 | Not system application. |
775| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
776
777**Example**
778
779```ts
780import { BusinessError } from '@ohos.base';
781try {
782  cooperate.prepare((error: BusinessError) => {
783    if (error) {
784      console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
785      return;
786    }
787    console.log(`Keyboard mouse crossing prepare success.`);
788  });
789} catch (error) {
790  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
791}
792```
793
794## cooperate.prepare<sup>(deprecated)</sup>
795
796prepare(): Promise&lt;void&gt;;
797
798Prepares for screen hopping. This API uses a promise to return the result.
799
800> **NOTE**
801>
802> This API is deprecated since API version 10. You are advised to use [cooperate.prepareCooperate](#cooperatepreparecooperate11-1).
803
804**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
805
806**Return value**
807
808| Parameters                | Description                    |
809| ------------------- | ------------------------------- |
810| Promise&lt;void&gt;      | Promise that returns no value.|
811
812**Error codes**
813
814For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
815
816| ID| Error Message         |
817| -------- | ----------------- |
818| 202 | Not system application. |
819| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
820
821**Example**
822
823```ts
824import { BusinessError } from '@ohos.base';
825try {
826  cooperate.prepare().then(() => {
827    console.log(`Keyboard mouse crossing prepare success.`);
828  }, (error: BusinessError) => {
829    console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
830  });
831} catch (error) {
832  console.log(`Keyboard mouse crossing prepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
833}
834```
835
836
837
838## cooperate.unprepare<sup>(deprecated)</sup>
839
840unprepare(callback: AsyncCallback&lt;void&gt;): void;
841
842Cancels the preparation for screen hopping. This API uses an asynchronous callback to return the result.
843
844> **NOTE**
845>
846> This API is deprecated since API version 10. You are advised to use [cooperate.unprepareCooperate](#cooperateunpreparecooperate11).
847
848**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
849
850| Name  | Type                     | Mandatory| Description                                      |
851| -------- | ------------------------- | ---- | ------------------------------------------ |
852| callback | AsyncCallback&lt;void&gt; | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
853
854**Error codes**
855
856For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
857
858| ID| Error Message         |
859| -------- | ----------------- |
860| 202 | Not system application. |
861| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
862
863**Example**
864
865```ts
866import { BusinessError } from '@ohos.base';
867try {
868  cooperate.unprepare((error: BusinessError) => {
869    if (error) {
870      console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
871      return;
872    }
873    console.log(`Keyboard mouse crossing unprepare success.`);
874  });
875} catch (error) {
876  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
877}
878```
879
880## cooperate.unprepare<sup>(deprecated)</sup>
881
882unprepare(): Promise&lt;void&gt;;
883
884Cancels the preparation for screen hopping. This API uses a promise to return the result.
885
886> **NOTE**
887>
888> This API is deprecated since API version 10. You are advised to use [cooperate.unprepareCooperate](#cooperateunpreparecooperate11-1).
889
890**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
891
892**Return value**
893
894| Parameters               | Description                                         |
895| ------------------- | --------------------------------------------- |
896| Promise&lt;void&gt; | Promise that returns no value.|
897
898**Error codes**
899
900For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
901
902| ID| Error Message         |
903| -------- | ----------------- |
904| 202 | Not system application. |
905| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
906
907**Example**
908
909```ts
910import { BusinessError } from '@ohos.base';
911try {
912  cooperate.unprepare().then(() => {
913    console.log(`Keyboard mouse crossing unprepare success.`);
914  }, (error: BusinessError) => {
915    console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
916  });
917} catch (error) {
918  console.log(`Keyboard mouse crossing unprepare failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
919}
920```
921
922
923
924## cooperate.activate<sup>(deprecated)</sup>
925
926activate(targetNetworkId: string, inputDeviceId: number, callback: AsyncCallback&lt;void&gt;): void;
927
928Starts screen hopping. This API uses an asynchronous callback to return the result.
929
930> **NOTE**
931>
932> This API is deprecated since API version 10. You are advised to use [cooperate.activateCooperate](#cooperateactivatecooperate11).
933
934**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
935
936**Parameters**
937
938| Name               | Type                         | Mandatory | Description                           |
939| --------             | ---------------------------- | ----  | ----------------------------   |
940| targetNetworkId | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
941| inputDeviceId | number                       |  Yes  | Identifier of the input device for screen hopping.|
942| callback             | AsyncCallback&lt;void&gt; |  Yes   | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
943
944**Error codes**
945
946For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
947
948| ID| Error Message|
949| -------- | ---------------------------------------- |
950| 20900001 | Operation failed.|
951| 202 | Not system application. |
952| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
953
954**Example**
955
956```ts
957import { BusinessError } from '@ohos.base';
958let targetNetworkId = "networkId";
959let inputDeviceId = 0;
960try {
961  cooperate.activate(targetNetworkId, inputDeviceId, (error: BusinessError) => {
962    if (error) {
963      console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
964      return;
965    }
966    console.log(`Start Keyboard mouse crossing success.`);
967  });
968} catch (error) {
969  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
970}
971```
972
973## cooperate.activate<sup>(deprecated)</sup>
974
975activate(targetNetworkId: string, inputDeviceId: number): Promise&lt;void&gt;;
976
977Starts screen hopping. This API uses a promise to return the result.
978
979> **NOTE**
980>
981> This API is deprecated since API version 10. You are advised to use [cooperate.activateCooperate](#cooperateactivatecooperate11-1).
982
983**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
984
985**Parameters**
986
987| Name               | Type                         | Mandatory | Description                           |
988| --------             | ---------------------------- | ----  | ----------------------------   |
989| targetNetworkId | string                       |  Yes  | Descriptor of the target device for screen hopping.            |
990| inputDeviceId | number                       |  Yes  | Identifier of the input device for screen hopping.|
991
992
993
994**Return value**
995
996| Name                 | Description                            |
997| ---------------------- | ------------------------------- |
998| Promise&lt;void&gt; | Promise that returns no value.    |
999
1000**Error codes**
1001
1002For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1003
1004| ID| Error Message|
1005| -------- | ---------------------------------------- |
1006| 20900001 | Operation failed.   |
1007| 202 | Not system application. |
1008| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1009
1010**Example**
1011
1012```ts
1013import { BusinessError } from '@ohos.base';
1014let targetNetworkId = "networkId";
1015let inputDeviceId = 0;
1016try {
1017 cooperate.activate(targetNetworkId, inputDeviceId).then(() => {
1018    console.log(`Start Keyboard mouse crossing success.`);
1019  }, (error: BusinessError) => {
1020    console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1021  });
1022} catch (error) {
1023  console.log(`Start Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1024}
1025```
1026
1027
1028
1029## cooperate.deactivate<sup>(deprecated)</sup>
1030
1031deactivate(isUnchained: boolean, callback: AsyncCallback&lt;void&gt;): void;
1032
1033Stops screen hopping. This API uses an asynchronous callback to return the result.
1034
1035> **NOTE**
1036>
1037> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperatedeactivatecooperate11).
1038
1039**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1040
1041**Parameters**
1042
1043| Name               | Type                         | Mandatory | Description                           |
1044| --------             | ---------------------------- | ----  | ----------------------------   |
1045| isUnchained | boolean | Yes| Whether to disable the cross-device link.<br> The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
1046| callback     | AsyncCallback&lt;void&gt; |  Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1047
1048**Error codes**
1049
1050For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1051
1052| ID| Error Message         |
1053| -------- | ----------------- |
1054| 202 | Not system application. |
1055| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1056
1057**Example**
1058
1059```ts
1060import { BusinessError } from '@ohos.base';
1061try {
1062  cooperate.deactivate(false, (error: BusinessError) => {
1063    if (error) {
1064      console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1065      return;
1066    }
1067    console.log(`Stop Keyboard mouse crossing success.`);
1068  });
1069} catch (error) {
1070  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1071}
1072```
1073
1074## cooperate.deactivate<sup>(deprecated)</sup>
1075
1076deactivate(isUnchained: boolean): Promise&lt;void&gt;;
1077
1078Stops screen hopping. This API uses a promise to return the result.
1079
1080> **NOTE**
1081>
1082> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperatedeactivatecooperate11-1).
1083
1084**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1085
1086**Parameters**
1087
1088| Name     | Type   | Mandatory| Description              |
1089| ----------- | ------- | ---- | ------------------ |
1090| isUnchained | boolean | Yes  | Whether to disable the cross-device link.<br> The value **true** means to disable the cross-device link, and the value **false** means the opposite.|
1091
1092
1093
1094**Return value**
1095
1096| Name               | Description                           |
1097| --------             | ----------------------------   |
1098| Promise&lt;void&gt; |  Promise that returns no value.     |
1099
1100**Error codes**
1101
1102For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1103
1104| ID| Error Message         |
1105| -------- | ----------------- |
1106| 202 | Not system application. |
1107
1108**Example**
1109
1110```ts
1111import { BusinessError } from '@ohos.base';
1112try {
1113  cooperate.deactivate(false).then(() => {
1114    console.log(`Stop Keyboard mouse crossing success.`);
1115  }, (error: BusinessError) => {
1116    console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1117  });
1118} catch (error) {
1119  console.log(`Stop Keyboard mouse crossing failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1120}
1121```
1122
1123
1124
1125## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1126
1127getCrossingSwitchState(networkId: string, callback: AsyncCallback&lt;boolean&gt;): void;
1128
1129Obtains the screen hopping status of the target device. This API uses an asynchronous callback to return the result.
1130
1131> **NOTE**
1132>
1133> This API is deprecated since API version 10. You are advised to use [cooperate.deactivateCooperate](#cooperategetcooperateswitchstate11).
1134
1135**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1136
1137**Parameters**
1138
1139| Name               | Type                         | Mandatory  | Description                           |
1140| --------             | ---------                    | ----  | ----------------------------    |
1141| networkId | string                       |  Yes   | Descriptor of the target device for screen hopping.            |
1142| callback             | AsyncCallback&lt;boolean&gt; |  Yes   | Callback used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
1143
1144**Error codes**
1145
1146For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1147
1148| ID| Error Message         |
1149| -------- | ----------------- |
1150| 202 | Not system application. |
1151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1152
1153**Example**
1154
1155```ts
1156import { BusinessError } from '@ohos.base';
1157let deviceDescriptor = "networkId";
1158try {
1159  cooperate.getCrossingSwitchState(deviceDescriptor, (error: BusinessError, data: boolean) => {
1160    if (error) {
1161      console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1162      return;
1163    }
1164    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1165  });
1166} catch (error) {
1167  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1168}
1169```
1170
1171## cooperate.getCrossingSwitchState<sup>(deprecated)</sup>
1172
1173getCrossingSwitchState(networkId: string): Promise&lt;boolean&gt;;
1174
1175Obtains the screen hopping status of the target device. This API uses a promise to return the result.
1176
1177> **NOTE**
1178>
1179> This API is deprecated since API version 10. You are advised to use [cooperate.getCooperateSwitchState](#cooperategetcooperateswitchstate11-1).
1180
1181**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1182
1183**Parameters**
1184
1185| Name   | Type  | Mandatory  | Description                           |
1186| --------   | ---------  | ----  | ----------------------------    |
1187| networkId | string     |  Yes   | Descriptor of the target device for screen hopping.           |
1188
1189**Error codes**
1190
1191For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1192
1193| ID| Error Message         |
1194| -------- | ----------------- |
1195| 202 | Not system application. |
1196| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1197
1198**Return value**
1199
1200| Parameters                       | Description                    |
1201| -------------------        | ------------------------------- |
1202| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that screen hopping is enabled, and the value **false** indicates the opposite.|
1203
1204
1205
1206**Example**
1207
1208```ts
1209import { BusinessError } from '@ohos.base';
1210let deviceDescriptor = "networkId";
1211try {
1212  cooperate.getCrossingSwitchState(deviceDescriptor).then((data: boolean) => {
1213    console.log(`Get the status success, data: ${JSON.stringify(data)}`);
1214  }, (error: BusinessError) => {
1215    console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1216  });
1217} catch (error) {
1218  console.log(`Get the status failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1219}
1220```
1221
1222
1223
1224## on('cooperate')<sup>(deprecated)</sup>
1225
1226on(type: 'cooperate', callback: Callback&lt;{ networkId: string, msg: CooperateMsg }&gt;): void;
1227
1228Enables listening for screen hopping status change events.
1229
1230> **NOTE**
1231>
1232> This API is deprecated since API version 10. You are advised to use [on('cooperateMessage')](#oncooperatemessage11).
1233
1234**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1235
1236**Parameters**
1237
1238| Name               | Type                                                            | Mandatory| Description                           |
1239| --------             | ----------------------------                                    | ---- | ----------------------------   |
1240| type                 | string                                                          |  Yes | Event type. The value is **cooperate**.|
1241| callback             | Callback&lt;{ networkId: string, msg: [CooperateMsg](#cooperatemsgdeprecated) }&gt; |  Yes | Callback used to return the result.|
1242
1243**Error codes**
1244
1245For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1246
1247| ID| Error Message         |
1248| -------- | ----------------- |
1249| 202 | Not system application. |
1250| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1251
1252**Example**
1253
1254```ts
1255function callback(networkId: string, msg: cooperate.CooperateMsg) {
1256  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1257  return false;
1258}
1259try {
1260  cooperate.on('cooperate', callback);
1261} catch (error) {
1262  console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1263}
1264```
1265
1266
1267
1268## off('cooperate')<sup>(deprecated)</sup>
1269
1270off(type: 'cooperate', callback?: Callback&lt;void&gt;): void;
1271
1272Disables listening for screen hopping status change events.
1273
1274> **NOTE**
1275>
1276> This API is deprecated since API version 10. You are advised to use [off('cooperateMessage')](#offcooperatemessage11).
1277
1278**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1279
1280**Parameters**
1281
1282| Name               | Type                                                             | Mandatory   | Description                          |
1283| --------             | ----------------------------                                     | ----   | ----------------------------   |
1284| type                 | string                                                           |  Yes   | Event type. The value is **cooperate**.|
1285| callback             | AsyncCallback&lt;void&gt; |  No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.|
1286
1287**Error codes**
1288
1289For details about the error codes, see [Screen Hopping Error Codes](errorcode-devicestatus.md).
1290
1291| ID| Error Message         |
1292| -------- | ----------------- |
1293| 202 | Not system application. |
1294| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.2.Incorrect parameter types.3.Parameter verification failed. |
1295
1296**Example**
1297
1298```ts
1299// Unregister a single callback.
1300function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1301  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1302  return false;
1303}
1304function callbackOff() {
1305  console.log(`Keyboard mouse crossing event`);
1306  return false;
1307}
1308try {
1309  cooperate.on('cooperate', callbackOn);
1310  cooperate.off('cooperate', callbackOff);
1311} catch (error) {
1312  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1313}
1314```
1315```ts
1316// Unregister all callbacks.
1317function callbackOn(networkId: string, msg: cooperate.CooperateMsg) {
1318  console.log(`Keyboard mouse crossing event: ${JSON.stringify(networkId)}`);
1319  return false;
1320}
1321try {
1322  cooperate.on('cooperate', callbackOn);
1323  cooperate.off('cooperate');
1324} catch (error) {
1325  console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
1326}
1327```
1328
1329
1330
1331##  CooperateMsg<sup>(deprecated)</sup>
1332
1333Represents a screen hopping message notification.
1334
1335> **NOTE**
1336>
1337> This API is deprecated since API version 10. You are advised to use [CooperateMessage](#cooperatemessage11).
1338
1339**System capability**: SystemCapability.Msdp.DeviceStatus.Cooperate
1340
1341| Name                      | Value                            | Description                             |
1342| --------                     |  -----------------               |  -----------------               |
1343| COOPERATE_PREPARE |  0    |  The preparation for screen hopping is finished.  |
1344| COOPERATE_UNPREPARE |  1  |  The preparation for screen hopping is cancelled. |
1345| COOPERATE_ACTIVATE |  2   |  Screen hopping starts. |
1346| COOPERATE_ACTIVATE_SUCCESS | 3 | Starting screen hopping succeeds.|
1347| COOPERATE_ACTIVATE_FAIL | 4 | Starting screen hopping fails.|
1348| COOPERATE_DEACTIVATE_SUCCESS | 5 | Stopping screen hopping succeeds.|
1349| COOPERATE_DEACTIVATE_FAIL | 6 | Stopping screen hopping fails.|
1350| COOPERATE_SESSION_DISCONNECTED | 7 | The screen hopping session is disconnected.|
1351