my.onUserCaptureScreen(CALLBACK)
Note
This API is supported in mPaaS 10.1.32 and later.
This API listens for user-initiated screen capture events. It receives notifications of these events from the system and third-party screen capture tools. Use my.offUserCaptureScreen() to cancel the listener.
Code example
<!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
<view class="page">
<view class="page-description">User Screen Capture Event API</view>
<view class="page-section">
<view class="page-section-title">my.onUserCaptureScreen</view>
<view class="page-section-demo">
<view>Current status: {{ condition ? "Listener enabled" : 'Listener canceled' }}</view>
<view a:if="{{condition}}">
<button type="primary" onTap="offUserCaptureScreen">Cancel screen event listener</button>
</view>
<view a:else>
<button type="primary" onTap="onUserCaptureScreen">Enable screen event listener</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: 'User screenshot received',
});
});
},
offUserCaptureScreen() {
my.offUserCaptureScreen();
this.setData({
condition: false,
});
},
onUserCaptureScreen() {
my.onUserCaptureScreen(() => {
my.alert({
content: 'User screenshot received'
});
});
this.setData({
condition: true,
});
},
});my.offUserCaptureScreen()
Note
This API is supported in mPaaS 10.1.32 and later.
This API cancels the screen capture event listener. It is typically used with my.onUserCaptureScreen.
Code example
<!-- API-DEMO page/API/user-capture-screen/user-capture-screen.axml-->
<view class="page">
<view class="page-description">User Screen Capture Event API</view>
<view class="page-section">
<view class="page-section-title">my.onUserCaptureScreen</view>
<view class="page-section-demo">
<view>Current status: {{ condition ? "Listener enabled" : 'Listener canceled' }}</view>
<view a:if="{{condition}}">
<button type="primary" onTap="offUserCaptureScreen">Cancel screen event listener</button>
</view>
<view a:else>
<button type="primary" onTap="onUserCaptureScreen">Enable screen event listener</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: 'User screenshot received',
});
});
},
offUserCaptureScreen() {
my.offUserCaptureScreen();
this.setData({
condition: false,
});
},
onUserCaptureScreen() {
my.onUserCaptureScreen(() => {
my.alert({
content: 'User screenshot received'
});
});
this.setData({
condition: true,
});
},
});Whether to pass a callback value
If no callback value is passed, all event callbacks are removed. The following code shows an example:
my.offUserCaptureScreen();If a callback value is passed, only the corresponding callback is removed. The following code shows an example:
my.offUserCaptureScreen(this.callback);