gpt4 book ai didi

javascript - 具有 ionic 框架的 Cordova 亮度插件

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:31:27 25 4
gpt4 key购买 nike

我正在使用 https://github.com/mgcrea/cordova-plugin-brightness

我已经找到在 Ionic 应用程序中工作的 setBrightness。但我无法弄清楚 getBrightness 的工作。任何关于如何让它工作的指示都将受到赞赏。

这是我的设置亮度:

  $scope.changeBrightness = function (newBrightness) {
myBrightness = parseFloat(newBrightness)/1000;
if (window.cordova && window.cordova.plugins.brightness) {
var LightControl = cordova.plugins.brightness;
LightControl.setBrightness(myBrightness);
}
}

LightControl.getBrightness();但是之后?我如何处理成功或失败?

最佳答案

getBrightness() 应该是处理成功和错误的回调函数。成功回调会返回设置的亮度值。该值将是一个介于 0 到 1 之间的 float 。在系统默认亮度的情况下返回 -1。

检查我在 vanilla cordova 项目中尝试的这个简单示例代码:

index.html

<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Brightness Control</title>
</head>
<body>
<br>
<br>
Set Brightness <input type="button" value="setbright" name="Wifi" id="setbright"/> <br>
Get Brightness <input type="button" value="getbright" name="Wifi" id="getbright"/> <br>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</body>
</html>

app.js

$(document).ready(function() {
document.addEventListener("deviceready", onDeviceReady, false);
});

function onDeviceReady() {

$('#setbright').click( function()
{
try {
cordova.plugins.brightness.setBrightness(0.9, setsuccess, seterror);
}
catch(err) {
alert("Plugin Error - " + err.message);
}

});

$('#getbright').click( function()
{
try {
cordova.plugins.brightness.getBrightness(getsuccess, geterror);
}
catch(err) {
alert("Plugin Error - " + err.message);
}

});

function setsuccess(e) {
alert("Brightness set successfully");
}

function getsuccess(e) {
alert("Brightness value - " + e);
}

function seterror(e) {
alert("Error setting brightness");
}

function geterror(e) {
alert("Error getting brightness");
}
}

关于javascript - 具有 ionic 框架的 Cordova 亮度插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37799654/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com