my.setKeepScreenOn(OBJECT)
说明:基础库 1.3.0 及以上版本支持该接口,低版本需要做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。
此接口用于设置是否保持屏幕长亮状态。仅在当前小程序生效,离开小程序后失效。
入参
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
keepScreenOn | Boolean | 是 | 是否保持屏幕长亮状态 |
success | Function | 否 | 接口调用成功的回调函数 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
代码示例
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
my.getScreenBrightness(OBJECT)
说明:基础库 1.4.0 及以上版本支持该接口,低版本需要做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。
此接口用于获取屏幕亮度。
入参
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 否 | 接口调用成功的回调函数 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
代码示例
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
my.setScreenBrightness(OBJECT)
说明:基础库 1.4.0 及以上版本支持该接口,低版本需要做兼容处理,操作参见 小程序基础库说明。mPaaS 10.1.32 及以上版本支持该接口。
此接口用于设置屏幕亮度。
入参
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
brightness | Number | 是 | 需要设置的屏幕亮度,取值范围为 0-1 |
success | Function | 否 | 接口调用成功的回调函数 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
代码示例
<!-- API-DEMO page/API/screen/screen.axml-->
<view class="page">
<view class="page-description">屏幕亮度 API</view>
<view class="page-section">
<view class="page-section-title">设置是否保持屏幕长亮状态</view>
<view class="page-section-demo">
<switch checked="{{status}}" onChange="switchKeepScreenOn"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">设置屏幕亮度</view>
<view class="page-section-demo">
<slider value="{{brightness}}" max="1" min="0" onChange="sliderChange" step="0.02"/>
</view>
</view>
<view class="page-section">
<view class="page-section-title">获取屏幕亮度</view>
<view class="page-section-demo">
<button type="primary" onTap="getBrightness">获取屏幕亮度</button>
</view>
</view>
</view>
// API-DEMO page/API/screen/screen.js
Page({
data: {
status: false,
brightness: 1,
},
onLoad() {
my.getScreenBrightness({
success: res => {
this.setData({
brightness: res.brightness
})
},
})
},
sliderChange(e) {
my.setScreenBrightness({
brightness: e.detail.value,
success: (res) => {
this.setData({
brightness: e.detail.value,
})
}
})
},
switchKeepScreenOn(e) {
my.setKeepScreenOn({
keepScreenOn: e.detail.value,
success: (res) => {
this.setData({
status: e.detail.value,
})
}
})
},
getBrightness() {
my.getScreenBrightness({
success: res => {
my.alert({
content: `当前屏幕亮度:${res.brightness}`
});
}
})
}
});
文档内容是否对您有帮助?