• 下载
  • 社区

my.onUserCaptureScreen

用于监听用户发起的主动截屏事件,可以接收到系统以及第三方截屏工具的截屏事件通知。


扫码体验

截屏事件.jpeg


效果示例

截屏事件.png


示例代码

 1<!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
 2<view class="page">
 3  <view class="page-description">用户截屏事件 API</view>
 4  <view class="page-section">
 5    <view class="page-section-title">my.onUserCaptureScreen</view>
 6    <view class="page-section-demo">
 7      <view>目前状态:{{ condition ? "已经开启监听" : '已经取消监听' }}</view>
 8      <view a:if="{{condition}}">
 9        <button type="primary" onTap="offUserCaptureScreen">取消监听屏幕事件</button>
10      </view>
11      <view a:else>
12        <button type="primary" onTap="onUserCaptureScreen">开启监听屏幕事件</button>
13      </view>
14    </view>
15  </view>
16</view>


 1// API-DEMO page/API/user-capture-screen/user-capture-screen.js
 2Page({
 3  data: {
 4    condition: false,
 5  },
 6  onReady() {
 7    my.onUserCaptureScreen(() => {
 8      my.alert({
 9        content: '收到用户截图',
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: '收到用户截图'
23      });
24    });
25    this.setData({
26      condition: true,
27    });
28  },
29});