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}`
});
}
})
}
});
文檔內容是否對您有幫助?