All Products
Search
Document Center

Capture screen

Last Updated: Feb 04, 2021

my.onUserCaptureScreen(CALLBACK)

Note: This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to listen to the screen capture events initiated by users, and can receive screen capture event notifications from the system and third-party screen capture tools. You can use the my.offUserCaptureScreen() to cancel listening.

Sample code

 
  1. <!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
  2. <view class="page">
  3. <view class="page-description">User screen capture event API</view>
  4. <view class="page-section">
  5. <view class="page-section-title">my.onUserCaptureScreen</view>
  6. <view class="page-section-demo">
  7. <view>Current status: {{ condition ? "listening on" : 'listening off' }}</view>
  8. <view a:if="{{condition}}">
  9. <button type="primary" onTap="offUserCaptureScreen">Cancel screen capture event listening</button>
  10. </view>
  11. <view a:else>
  12. <button type="primary" onTap="onUserCaptureScreen">Enable screen capture event listening</button>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
 
  1. // API-DEMO page/API/user-capture-screen/user-capture-screen.js
  2. Page({
  3. data: {
  4. condition: false,
  5. },
  6. onReady() {
  7. my.onUserCaptureScreen(() => {
  8. my.alert({
  9. content: 'Received user screen capture',
  10. });
  11. });
  12. },
  13. offUserCaptureScreen() {
  14. my.offUserCaptureScreen();
  15. this.setData({
  16. condition: false,
  17. });
  18. },
  19. onUserCaptureScreen() {
  20. my.onUserCaptureScreen(() => {
  21. my.alert({
  22. content: 'Received user screen capture'
  23. });
  24. });
  25. this.setData({
  26. condition: true,
  27. });
  28. },
  29. });
 

my.offUserCaptureScreen()

Note: This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to cancel the listening of screen capture events. It is usually paired with my.onUserCaptureScreen.

Sample code

 
  1. <!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
  2. <view class="page">
  3. <view class="page-description">User screen capture event API</view>
  4. <view class="page-section">
  5. <view class="page-section-title">my.onUserCaptureScreen</view>
  6. <view class="page-section-demo">
  7. <view>Current status: {{ condition ? "listening on" : 'listening off' }}</view>
  8. <view a:if="{{condition}}">
  9. <button type="primary" onTap="offUserCaptureScreen">Cancel screen capture event listening</button>
  10. </view>
  11. <view a:else>
  12. <button type="primary" onTap="onUserCaptureScreen">Enable screen capture event listening</button>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
 
  1. // API-DEMO page/API/user-capture-screen/user-capture-screen.js
  2. Page({
  3. data: {
  4. condition: false,
  5. },
  6. onReady() {
  7. my.onUserCaptureScreen(() => {
  8. my.alert({
  9. content: 'Received user screen capture',
  10. });
  11. });
  12. },
  13. offUserCaptureScreen() {
  14. my.offUserCaptureScreen();
  15. this.setData({
  16. condition: false,
  17. });
  18. },
  19. onUserCaptureScreen() {
  20. my.onUserCaptureScreen(() => {
  21. my.alert({
  22. content: 'Received user screen capture'
  23. });
  24. });
  25. this.setData({
  26. condition: true,
  27. });
  28. },
  29. });

Whether to pass callback value or not

  • If the callback value is not passed, the callbacks of all events will be removed. The sample code is as follows:
       
    1. my.offUserCaptureScreen();
  • If the callback value is passed, only the corresponding callback is removed. The sample code is as follows:
       
    1. my.offUserCaptureScreen(this.callback);