支付寶小程序API 用戶截屏事件

2020-09-15 11:42 更新

my.onUserCaptureScreen

用于監(jiān)聽(tīng)用戶發(fā)起的主動(dòng)截屏事件,可以接收到系統(tǒng)以及第三方截屏工具的截屏事件通知??墒褂?my.offUserCaptureScreen() 取消監(jiān)聽(tīng)。

掃碼體驗(yàn)

截屏事件.jpeg

效果示例

截屏事件.png

示例代碼

<!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
<view class="page">
  <view class="page-description">用戶截屏事件 API</view>
  <view class="page-section">
    <view class="page-section-title">my.onUserCaptureScreen</view>
    <view class="page-section-demo">
      <view>目前狀態(tài):{{ condition ? "已經(jīng)開(kāi)啟監(jiān)聽(tīng)" : '已經(jīng)取消監(jiān)聽(tīng)' }}</view>
      <view a:if="{{condition}}">
        <button type="primary" onTap="offUserCaptureScreen">取消監(jiān)聽(tīng)屏幕事件</button>
      </view>
      <view a:else>
        <button type="primary" onTap="onUserCaptureScreen">開(kāi)啟監(jiān)聽(tīng)屏幕事件</button>
      </view>
    </view>
  </view>
</view>
// API-DEMO page/API/user-capture-screen/user-capture-screen.js
Page({
  data: {
    condition: false,
  },
  onReady() {
    my.onUserCaptureScreen(() => {
      my.alert({
        content: '收到用戶截圖',
      });
    });
  },
  offUserCaptureScreen() {
    my.offUserCaptureScreen();
    this.setData({
      condition: false,
    });
  },
  onUserCaptureScreen() {
    my.onUserCaptureScreen(() => {
      my.alert({
        content: '收到用戶截圖'
      });
    });
    this.setData({
      condition: true,
    });
  },
});

my.offUserCaptureScreen

取消監(jiān)聽(tīng)截屏事件。

掃碼體驗(yàn)

截屏事件.jpeg

效果示例

取消截屏.png

示例代碼

<!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
<view class="page">
  <view class="page-description">用戶截屏事件 API</view>
  <view class="page-section">
    <view class="page-section-title">my.onUserCaptureScreen</view>
    <view class="page-section-demo">
      <view>目前狀態(tài):{{ condition ? "已經(jīng)開(kāi)啟監(jiān)聽(tīng)" : '已經(jīng)取消監(jiān)聽(tīng)' }}</view>
      <view a:if="{{condition}}">
        <button type="primary" onTap="offUserCaptureScreen">取消監(jiān)聽(tīng)屏幕事件</button>
      </view>
      <view a:else>
        <button type="primary" onTap="onUserCaptureScreen">開(kāi)啟監(jiān)聽(tīng)屏幕事件</button>
      </view>
    </view>
  </view>
</view>
// API-DEMO page/API/user-capture-screen/user-capture-screen.js
Page({
  data: {
    condition: false,
  },
  onReady() {
    my.onUserCaptureScreen(() => {
      my.alert({
        content: '收到用戶截圖',
      });
    });
  },
  offUserCaptureScreen() {
    my.offUserCaptureScreen();
    this.setData({
      condition: false,
    });
  },
  onUserCaptureScreen() {
    my.onUserCaptureScreen(() => {
      my.alert({
        content: '收到用戶截圖'
      });
    });
    this.setData({
      condition: true,
    });
  },
});
是否需要傳 callback 值

  • 不傳遞 callback 值,則會(huì)移除監(jiān)聽(tīng)所有的事件回調(diào)。示例代碼如下:

my.offUserCaptureScreen();
  • 傳遞 callback 值,只移除對(duì)應(yīng)的 callback 事件。示例代碼如下:

my.offUserCaptureScreen(this.callback);
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)