屏幕API
ty.getScreenBrightness
获取手机屏幕亮度
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
object.success 回调参数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
value | number | 屏幕亮度值,范围 0 ~ 1。0 最暗,1 最亮 |
object.fail 回调参数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
errorMsg | string | 插件错误信息 |
errorCode | string | 错误码 |
innerError | object | 插件外部依赖错误信息 {errorMsg: string, errorCode: string } |
函数定义示例
/**
* 获取屏幕亮度
*/
export function getScreenBrightness(params?: {
complete?: () => void;
success?: (params: {
/** 屏幕亮度值,范围 0 ~ 1。0 最暗,1 最亮 */
value: number;
}) => void;
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
ty.setKeepScreenOn
设置是否保持常亮状态
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
keepScreenOn | boolean | 是 | 是否保持屏幕常亮 | |
complete | function | 否 | 接口调用完成的回调函数(成功或失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 设置是否保持常亮状态
*/
export function setKeepScreenOn(params: {
/** 是否保持屏幕常亮 */
keepScreenOn: boolean;
complete?: () => void;
success?: (params: null) => void;
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
ty.setScreenBrightness
设置手机屏幕亮度
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
value | number | 是 | 屏幕亮度值,范围 0 ~ 1。0 最暗,1 最亮 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 设置屏幕亮度
*/
export function setScreenBrightness(params: {
/** 屏幕亮度值,范围 0 ~ 1。0 最暗,1 最亮 */
value: number;
complete?: () => void;
success?: (params: null) => void;
fail?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
👉 立即开发。
设备方向API
ty.startDeviceMotionListening
开始监听设备方向的变化。
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
interval | DeviceMotionInterval | 否 | 监听加速度数据回调函数的执行频率 | |
complete | function | 否 | 接口调用完成的回调函数(成功或失败都会调用) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 开始监听设备方向的变化。
*/
export function startDeviceMotionListening(params?: {
/** 监听加速度数据回调函数的执行频率 */
interval?: DeviceMotionInterval;
complete?: () => void;
success?: (params: null) => void;
failure?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
ty.stopDeviceMotionListening
停止监听设备方向的变化。
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
Object object
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 |
函数定义示例
/**
* 停止监听设备方向的变化。
*/
export function stopDeviceMotionListening(params?: {
complete?: () => void;
success?: (params: null) => void;
failure?: (params: {
errorMsg: string;
errorCode: string | number;
innerError: {
errorCode: string | number;
errorMsg: string;
};
}) => void;
}): void;
ty.onDeviceMotionChange
监听设备方向变化事件
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
function callback
监听设备方向变化事件的回调函数
回调参数 Object res
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
alpha | number | 是 | 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 | |
beta | number | 是 | 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 | |
gamma | number | 是 | 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 |
函数定义示例
/**
* 监听设备方向变化事件
*/
export function onDeviceMotionChange(
listener: (params: {
/** 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 */
alpha: number;
/** 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 */
beta: number;
/** 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 */
gamma: number;
}) => void,
): void;
ty.offDeviceMotionChange
取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
需引入
BaseKit
,且在>=2.3.2
版本才可使用
参数
function callback
取消监听设备方向变化事件的回调函数。参数为空,则取消所有的事件监听。
回调参数 Object res
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
alpha | number | 是 | 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 | |
beta | number | 是 | 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 | |
gamma | number | 是 | 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 |
函数定义示例
/**
* 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
*/
export function offDeviceMotionChange(
listener: (params: {
/** 当 手机坐标 X/Y 和 地球 X/Y 重合时,绕着 Z 轴转动的夹角为 alpha,范围值为 [0, 2*PI)。逆时针转动为正。 */
alpha: number;
/** 当手机坐标 Y/Z 和地球 Y/Z 重合时,绕着 X 轴转动的夹角为 beta。范围值为 [-1*PI, PI) 。顶部朝着地球表面转动为正。也有可能朝着用户为正。 */
beta: number;
/** 当手机 X/Z 和地球 X/Z 重合时,绕着 Y 轴转动的夹角为 gamma。范围值为 [-1*PI/2, PI/2)。右边朝着地球表面转动为正。 */
gamma: number;
}) => void,
): void;
👉 立即开发。