设备 - Device
# Device
> Stability: 2 - Stable
device模块提供了与设备有关的信息与操作,例如获取设备宽高,内存使用率,IMEI,调整设备亮度、音量等。
此模块的部分函数,例如调整音量,需要"修改系统设置"的权限。如果没有该权限,会抛出`SecurityException`并跳转到权限设置界面。
## 取分辨率宽度 |width
| 函数名 | 返回值 | 备注 |
| ------------ | ------ | ------------------------------ |
| device.width | 整数型 | 设备屏幕分辨率宽度。例如1080。 |
device.width
* {number}
设备屏幕分辨率宽度。例如1080。
## 取分辨率高度 |height
| 函数名 | 返回值 | 备注 |
| ------------- | ------ | ------------------------------ |
| device.height | 整数型 | 设备屏幕分辨率高度。例如1920。 |
device.height
* {number}
设备屏幕分辨率高度。例如1920。
## 取修订版本号 |buildId
| 函数名 | 返回值 | 备注 |
| -------------- | ------ | ------------------------------------- |
| device.buildId | 字符串 | 修订版本号,或者诸如\"M4-rc20\"的标识。 |
device.buildId
* {string}
Either a change list number, or a label like "M4-rc20".
修订版本号,或者诸如"M4-rc20"的标识。
## 取主板型号 |broad
| 函数名 | 返回值 | 备注 |
| ------------ | ------ | ------------------- |
| device.broad | 字符串 | 设备的主板(?)型号。 |
device.broad
* {string}
The name of the underlying board, like "goldfish".
设备的主板(?)型号。
## 取厂商品牌 |brand
| 函数名 | 返回值 | 备注 |
| ------------ | ------ | -------------------------------------- |
| device.brand | 字符串 | 硬件厂商品牌,如\"Xiaomi\", \"Huawei\"等。 |
device.brand
* {string}
The consumer-visible brand with which the product/hardware will be associated, if any.
与产品或硬件相关的厂商品牌,如"Xiaomi", "Huawei"等。
## 取设备名称 |device
| 函数名 | 返回值 | 备注 |
| ------------- | ------ | ------------------------ |
| device.device | 字符串 | 设备在工业设计中的名称。 |
device.device
* {string}
The name of the industrial design.
设备在工业设计中的名称。
## 取设备型号 |model
| 函数名 | 返回值 | 备注 |
| ------------ | ------ | ---------- |
| deivce.model | 字符串 | 设备型号。 |
device.model
* {string}
The end-user-visible name for the end product.
设备型号。
## 取产品名称 |product
| 函数名 | 返回值 | 备注 |
| -------------- | ------ | ---------------- |
| device.product | 字符串 | 整个产品的名称。 |
device.product
* {string}
The name of the overall product.
整个产品的名称。
## 取蓝牙版本 |bootloader
| 函数名 | 返回值 | 备注 |
| ----------------- | ------ | ---------------- |
| device.bootloader | 字符串 | 设备蓝牙的版本。 |
device.bootloader
* {string}
The system bootloader version number.
设备Bootloader的版本。
## 取硬件名称 |hardware
| 函数名 | 返回值 | 备注 |
| --------------- | ------ | ----------------------------------------- |
| device.hardware | 字符串 | 设备的硬件名称(来自内核命令行或者/proc)。 |
device.hardware
* {string}
The name of the hardware (from the kernel command line or /proc).
设备的硬件名称(来自内核命令行或者/proc)。
## 取唯一标识码 |fingerprint
| 函数名 | 返回值 | 备注 |
| ------------------ | ------ | ------------------------- |
| device.fingerprint | 字符串 | 构建(build)的唯一标识码。 |
device.fingerprint
* {string}
A string that uniquely identifies this build. Do not attempt to parse this value.
构建(build)的唯一标识码。
## 取硬件序列号 |serial
| 函数名 | 返回值 | 备注 |
| ------------- | ------ | ------------ |
| device.serial | 字符串 | 硬件序列号。 |
device.serial
* {string}
A hardware serial number, if available. Alphanumeric only, case-insensitive.
硬件序列号。
## 取安卓SDK |sdkInt
| 函数名 | 返回值 | 备注 |
| ------------- | ------ | ------------------------------------------ |
| device.sdkInt | 整数型 | 安卓系统SDK版本。例如安卓4.4的sdkInt为19。 |
device.sdkInt
* {number}
The user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES.
安卓系统API版本。例如安卓4.4的sdkInt为19。
## device.incremental
* {string}
The internal value used by the underlying source control to represent this build. E.g., a perforce change list number or a git hash.
## 取安卓系统版本 |release
| 函数名 | 返回值 | 备注 |
| -------------- | ------ | --------------------------------------- |
| device.release | 字符串 | Android系统版本号。例如\"5.0\", \"7.1.1\"。 |
device.release
* {string}
The user-visible version string. E.g., "1.0" or "3.4b5".
Android系统版本号。例如"5.0", "7.1.1"。
## device.baseOS
* {string}
The base OS build the product is based on.
## 取安全补丁 |securityPatch
| 函数名 | 返回值 | 备注 |
| -------------------- | ------ | -------------------- |
| deivce.securityPatch | 字符串 | 安全补丁程序级别。。 |
device.securityPatch
* {string}
The user-visible security patch level.
安全补丁程序级别。
## 取开发代号 |codename
| 函数名 | 返回值 | 备注 |
| --------------- | ------ | ------------------------------- |
| device.codename | 字符串 | 开发代号,例如发行版是\"REL\"。。 |
device.codename
* {string}
The current development codename, or the string "REL" if this is a release build.
开发代号,例如发行版是"REL"。
## 取设备IMEI |getIMEI
| 函数名 | 返回值 | 备注 |
| ---------------- | ------ | ---------------- |
| device.getIMEI() | 字符串 | 返回设备的IMEI。 |
device.getIMEI()
* {string}
返回设备的IMEI.
## 取安卓系统ID |getAndroidId
| 函数名 | 返回值 | 备注 |
| --------------------- | ------ | ---------------------- |
| device.getAndroidId() | 字符串 | 返回设备的Android ID。 |
device.getAndroidId()
* {string}
返回设备的Android ID。
Android ID为一个用16进制字符串表示的64位整数,在设备第一次使用时随机生成,之后不会更改,除非恢复出厂设置。
## 取设备Mac地址 |getMacAddress
| 函数名 | 返回值 | 备注 |
| ---------------------- | ------ | ------------------------------------------------------------ |
| device.getMacAddress() | 字符串 | 设备的Mac地址。该函数需要在有WLAN连接的情况下才能获取,否则会返回null。 |
device.getMacAddress()
* {string}
返回设备的Mac地址。该函数需要在有WLAN连接的情况下才能获取,否则会返回null。
**可能的后续修改**:未来可能增加有root权限的情况下通过root权限获取,从而在没有WLAN连接的情况下也能返回正确的Mac地址,因此请勿使用此函数判断WLAN连接。
## 取屏幕亮度 |getBrightness
| 函数名 | 返回值 | 备注 |
| ---------------------- | ------ | ----------------------------------- |
| device.getBrightness() | 整数型 | 返回当前的(手动)亮度。范围为0~255。 |
device.getBrightness()
* {number}
返回当前的(手动)亮度。范围为0~255。
## 取亮度模式 |getBrightnessMode
| 函数名 | 返回值 | 备注 |
| -------------------------- | ------ | -------------------------------------------- |
| device.getBrightnessMode() | 字符串 | 返回当前亮度模式,0为手动亮度,1为自动亮度。 |
device.getBrightnessMode()
* {number}
返回当前亮度模式,0为手动亮度,1为自动亮度。
## 设置屏幕亮度 |setBrightness
| 函数名 | 返回值 | 备注 |
| ---------------------- | -------- | ------------------------------------------------------------ |
| device.setBrightness() | | 设置当前手动亮度。如果当前是自动亮度模式,该函数不会影响屏幕的亮度。 |
| **参数名** | **类型** | |
| 亮度 | 整数型 | 范围0~255 |
device.setBrightness(b)
* `b` {number} 亮度,范围0~255
设置当前手动亮度。如果当前是自动亮度模式,该函数不会影响屏幕的亮度。
此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
## 设置亮度模式 |setBrightnessMode
| 函数名 | 返回值 | 备注 |
| -------------------------- | -------- | -------------------------- |
| device.setBrightnessMode() | | 设置当前亮度模式。 |
| **参数名** | **类型** | |
| 模式 | 整数型 | 0为手动亮度,1为自动亮度。 |
device.setBrightnessMode(mode)
* `mode` {number} 亮度模式,0为手动亮度,1为自动亮度
设置当前亮度模式。
此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
## 取媒体音量 |getMusicVolume
| 函数名 | 返回值 | 备注 |
| ----------------------- | ------ | ------------------ |
| device.getMusicVolume() | 整数型 | 返回当前媒体音量。 |
device.getMusicVolume()
* {number} 整数值
返回当前媒体音量。
## 取通知音量 |getNotificationVolume
| 函数名 | 返回值 | 备注 |
| ------------------------------ | ------ | ------------------ |
| device.getNotificationVolume() | 整数型 | 返回当前通知音量。 |
device.getNotificationVolume()
* {number} 整数值
返回当前通知音量。
## 取闹钟音量 |getAlarmVolume
| 函数名 | 返回值 | 备注 |
| ----------------------- | ------ | ------------------ |
| device.getAlarmVolume() | 整数型 | 返回当前闹钟音量。 |
device.getAlarmVolume()
* {number} 整数值
返回当前闹钟音量。
## 取媒体音量最大值 |getMusicMaxVolume
| 函数名 | 返回值 | 备注 |
| -------------------------- | ------ | ---------------------- |
| device.getMusicMaxVolume() | 整数型 | 返回媒体音量的最大值。 |
device.getMusicMaxVolume()
* {number} 整数值
返回媒体音量的最大值。
## 取通知音量最大值 |getNotificationMaxVolume
| 函数名 | 返回值 | 备注 |
| --------------------------------- | ------ | ---------------------- |
| device.getNotificationMaxVolume() | 整数型 | 返回通知音量的最大值。 |
device.getNotificationMaxVolume()
* {number} 整数值
返回通知音量的最大值。
## 取闹钟音量最大值 |getAlarmMaxVolume
| 函数名 | 返回值 | 备注 |
| -------------------------- | ------ | ---------------------- |
| device.getAlarmMaxVolume() | 整数型 | 返回闹钟音量的最大值。 |
device.getAlarmMaxVolume()
* {number} 整数值
返回闹钟音量的最大值。
## 设置媒体音量 |setMusicVolume
| 函数名 | 返回值 | 备注 |
| ----------------------- | -------- | ------------------ |
| device.setMusicVolume() | | 设置当前媒体音量。 |
| **参数名** | **类型** | |
| 音量 | 整数型 | |
device.setMusicVolume(volume)
* `volume` {number} 音量
设置当前媒体音量。
此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
## 设置通知音量 |setNotificationVolume
| 函数名 | 返回值 | 备注 |
| ------------------------------ | -------- | ------------------ |
| device.setNotificationVolume() | | 设置当前通知音量。 |
| **参数名** | **类型** | |
| 音量 | 整数型 | |
device.setNotificationVolume(volume)
* `volume` {number} 音量
设置当前通知音量。
此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
## 设置闹钟音量 |setAlarmVolume
| 函数名 | 返回值 | 备注 |
| ----------------------- | -------- | ------------------ |
| device.setAlarmVolume() | 整数型 | 设置当前闹钟音量。 |
| **参数名** | **类型** | |
| 音量 | 整数型 | |
device.setAlarmVolume(volume)
* `volume` {number} 音量
设置当前闹钟音量。
此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
## 取电量百分比 |getBattery
| 函数名 | 返回值 | 备注 |
| ------------------- | ------ | -------------------- |
| device.getBattery() | 浮点数 | 返回当前电量百分比。 |
device.getBattery()
* {number} 0.0~100.0的浮点数
返回当前电量百分比。
## 取充电状态 |isCharging
| 函数名 | 返回值 | 备注 |
| ------------------- | ------ | ---------------------- |
| device.isCharging() | 布尔型 | 返回设备是否正在充电。 |
device.isCharging()
* {boolean}
返回设备是否正在充电。
## 取内存总量 |getTotalMem
| 函数名 | 返回值 | 备注 |
| -------------------- | ------ | --------------------------------------------------- |
| device.getTotalMem() | 整数型 | 返回设备内存总量,单位字节(B)。1MB = 1024 * 1024B。 |
device.getTotalMem()
* {number}
返回设备内存总量,单位字节(B)。1MB = 1024 * 1024B。
## 取可用内存 |getAvailMem
| 函数名 | 返回值 | 备注 |
| -------------------- | ------ | ------------------------------------- |
| device.getAvailMem() | 整数型 | 返回设备当前可用的内存,单位字节(B)。 |
device.getAvailMem()
* {number}
返回设备当前可用的内存,单位字节(B)。
## 取屏幕状态 |isScreenOn
| 函数名 | 返回值 | 备注 |
| ------------------- | ------ | -------------------------- |
| device.isScreenOn() | 布尔型 | 返回设备屏幕是否是亮着的。 |
device.isScreenOn()
* 返回 {boolean}
返回设备屏幕是否是亮着的。如果屏幕亮着,返回`true`; 否则返回`false`。
需要注意的是,类似于vivo xplay系列的息屏时钟不属于"屏幕亮着"的情况,虽然屏幕确实亮着但只能显示时钟而且不可交互,此时`isScreenOn()`也会返回`false`。
## 唤醒设备 |wakeUp
| 函数名 | 返回值 | 备注 |
| --------------- | ------ | ----------------------------------------------------- |
| device.wakeUp() | | 唤醒设备。包括唤醒设备CPU、屏幕等。可以用来点亮屏幕。 |
device.wakeUp()
唤醒设备。包括唤醒设备CPU、屏幕等。可以用来点亮屏幕。
## device.wakeUpIfNeeded()
如果屏幕没有点亮,则唤醒设备。
## 设置屏幕常亮时间 |keepScreenOn
| 函数名 | 返回值 | 备注 |
| --------------------- | -------- | ------------------------------------------------------------ |
| device.keepScreenOn() | | 保持屏幕常亮。 |
| **参数名** | **类型** | |
| 时间 | 整数型 | 屏幕保持常亮的时间,单位毫秒。如果不加此参数,则一直保持屏幕常亮。 |
device.keepScreenOn([timeout])
* `timeout` {number} 屏幕保持常亮的时间, 单位毫秒。如果不加此参数,则一直保持屏幕常亮。
保持屏幕常亮。
此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
在某些设备上,如果不加参数timeout,只能在Auto.js的界面保持屏幕常亮,在其他界面会自动失效,这是因为设备的省电策略造成的。因此,建议使用比较长的时长来代替"一直保持屏幕常亮"的功能,例如`device.keepScreenOn(3600 * 1000)`。
可以使用`device.cancelKeepingAwake()`来取消屏幕常亮。
```
//一直保持屏幕常亮
device.keepScreenOn()
```
## 设置屏幕常亮时间 |keepScreenDim
| 函数名 | 返回值 | 备注 |
| ---------------------- | ------ | ------------------------------------------------------------ |
| device.keepScreenDim() | | 保持屏幕常亮,但允许屏幕变暗来节省电量。 |
| | | |
| 时间 | 整数型 | 屏幕保持常亮的时间, 单位毫秒。如果不加此参数,则一直保持屏幕常亮 |
device.keepScreenDim([timeout])
* `timeout` {number} 屏幕保持常亮的时间, 单位毫秒。如果不加此参数,则一直保持屏幕常亮。
保持屏幕常亮,但允许屏幕变暗来节省电量。此函数可以用于定时脚本唤醒屏幕操作,不需要用户观看屏幕,可以让屏幕变暗来节省电量。
此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
可以使用`device.cancelKeepingAwake()`来取消屏幕常亮。
## 取消设备唤醒状态 |cancelKeepingAwake
| 函数名 | 返回值 | 备注 |
| --------------------------- | ------ | ---------------------- |
| device.cancelKeepingAwake() | | 取消设备保持唤醒状态。 |
device.cancelKeepingAwake()
取消设备保持唤醒状态。用于取消`device.keepScreenOn()`, `device.keepScreenDim()`等函数设置的屏幕常亮。
## 设备震动 |vibrate
| 函数名 | 返回值 | 备注 |
| ---------------- | -------- | -------------------- |
| device.vibrate() | | 使设备震动一段时间。 |
| **参数名** | **类型** | |
| 震动时间 | 整数型 | 单位毫秒 |
device.vibrate(ms)
* `ms` {number} 震动时间,单位毫秒
使设备震动一段时间。
```
//震动两秒
device.vibrate(2000);
```
## 取消震动 |cancelVibration
| 函数名 | 返回值 | 备注 |
| ------------------------ | ------ | ---------------------------------- |
| device.cancelVibration() | | 如果设备处于震动状态,则取消震动。 |
device.cancelVibration()
如果设备处于震动状态,则取消震动。
# 示例
## 获取设备信息1
> 对官方例子做了补充
```js
console.show();
var str = "";
str += "屏幕宽度:" + device.width;
str += "\
屏幕高度:" + device.height;
str += "\
buildId:" + device.buildId; //修订版本号
str += "\
主板:" + device.board;
str += "\
制造商:" + device.brand;
str += "\
工业设计名称:" + device.device;
str += "\
产品名称:" + device.product;
str += "\
型号:" + device.model;
str += "\
bootloader版本:" + device.bootloader;
str += "\
硬件名称:" + device.hardware;
str += "\
唯一标识码:" + device.fingerprint;
str += "\
硬件序列号:"+device.serial;
str += "\
Incremental:"+device.incremental;
str += "\
Android系统版本号:"+device.release;
str += "\
BaseOS:"+device.baseOS;
str += "\
安全补丁程序级别:"+device.securityPatch;
str += "\
开发代号:"+device.codename;
str += "\
内存总量:"+device.getTotalMem();
str += "\
当前可用内存:"+device.getAvailMem();
str += "\
AndroidId: " + device.getAndroidId();
str += "\
Mac: " + device.getMacAddress();
str += "\
API: " + device.sdkInt;
str += "\
电量: " + device.getBattery();
str += "\
IMEI: " + device.getIMEI(); //需要读取设备信息权限
log(str);
```
以红米NOTE5高配版为例。运行结果如下:
>屏幕宽度:720
屏幕高度:1280
buildId:N2G47H
主板:QC_Reference_Phone
制造商:xiaomi
工业设计名称:ugg
产品名称:ugg
型号:Redmi Note 5A
bootloader版本:unknown
硬件名称:qcom
唯一标识码:xiaomi/ugg/ugg:7.1.2/N2G47H/V9.6.3.0.NDKCNFD:user/release-keys
硬件序列号:d0161d
Incremental:V9.6.3.0.NDKCNFD
Android系统版本号:7.1.2
BaseOS:
安全补丁程序级别:2018-07-01
开发代号:REL
内存总量:2982748160
当前可用内存:670408701
AndroidId: 75ce36b35fc495c1
Mac: 80:35:C1:1C:D6:F1
API: 25
电量: 91
## 获取设备信息2
```js
//from:https://thbelief.coding.me/2019/04/17/Auto-js-Script开发-十/
function mainUI(){
ui.layout(
<frame>
<vertical gravity="center">
<text gravity="center" text="设备信息" textSize="30sp" textColor="#000000"/>
<text gravity="center" id="Width" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Height" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="BuildId" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Broad" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Brand" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Device" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Model" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Product" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Bootloader" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Hardware" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Fingerprint" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Serial" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="SdkInt" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Incremental" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Release" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="BaseOS" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="SecurityPatch" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="Codename" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="GetAndroidId" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="GetMacAddress" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="GetTotalMem" text="" textSize="15sp" textColor="#000000"/>
<text gravity="center" id="GetAvailMem" text="" textSize="15sp" textColor="#000000"/>
</vertical>
</frame>
);
ui.Width.setText("设备宽度: "+device.width);
ui.Height.setText("设备高度: "+device.height);
ui.BuildId.setText("修订版本号: "+device.buildId);
ui.Broad.setText("主板型号: "+device.broad);
ui.Brand.setText("厂商品牌: "+device.brand);
ui.Device.setText("工业设计名称: "+device.device);
ui.Model.setText("设备型号: "+device.model);
ui.Product.setText("整个产品名称: "+device.product);
ui.Bootloader.setText("Bootloader版本: "+device.bootloader);
ui.Hardware.setText("硬件名称: "+device.hardware);
ui.Fingerprint.setText("唯一标识码: "+device.fingerprint);
ui.Serial.setText("硬件序列号: "+device.serial);
ui.SdkInt.setText("AndroidAPI版本: "+device.sdkInt);
ui.Incremental.setText("Incremental: "+device.incremental);
ui.Release.setText("Android系统版本号: "+device.release);
ui.BaseOS.setText("BaseOS: "+device.baseOS);
ui.SecurityPatch.setText("安全补丁程序级别: "+device.securityPatch);
ui.Codename.setText("开发代号: "+device.codename);
ui.GetAndroidId.setText("AndroidId: "+device.getAndroidId());
ui.GetMacAddress.setText("Mac地址: "+device.getMacAddress());
ui.GetTotalMem.setText("内存总量: "+device.getTotalMem());
ui.GetAvailMem.setText("当前可用内存: "+device.getAvailMem());
};
```
## 调整设备亮度
```js
"ui";
ui.layout(
<vertical padding="16">
<checkbox id="auto" text="自动亮度"/>
<text textColor="black" textSize="16sp" margin="8">亮度</text>
<seekbar id="brightness" max="100"/>
</vertical>
);
//getBrightnessMode()返回亮度模式,1为自动亮度
ui.auto.setChecked(device.getBrightnessMode() == 1);
ui.auto.setOnCheckedChangeListener(function(v, checked){
device.setBrightnessMode(checked ? 1: 0);
});
ui.brightness.setProgress(device.getBrightness());
ui.brightness.setOnSeekBarChangeListener({
onProgressChanged: function(seekbar, p, fromUser){
if(fromUser){
device.setBrightness(p);
}
}
});
```
## 调整设备音量
```js
"ui";
ui.layout(
<vertical padding="16">
<text textColor="black" textSize="16sp">媒体音量</text>
<seekbar id="music"/>
<text textColor="black" textSize="16sp">通知音量</text>
<seekbar id="notification"/>
<text textColor="black" textSize="16sp">闹钟音量</text>
<seekbar id="alarm"/>
</vertical>
);
ui.music.setMax(device.getMusicMaxVolume());
ui.music.setProgress(device.getMusicVolume());
ui.music.setOnSeekBarChangeListener({
onProgressChanged: function(seekbar, p, fromUser){
if(fromUser){
device.setMusicVolume(p);
}
}
});
ui.notification.setMax(device.getNotificationMaxVolume());
ui.notification.setProgress(device.getAlarmVolume());
ui.notification.setOnSeekBarChangeListener({
onProgressChanged: function(seekbar, p, fromUser){
if(fromUser){
device.setNotificationVolume(p);
}
}
});
ui.alarm.setMax(device.getAlarmMaxVolume());
ui.alarm.setProgress(device.getAlarmVolume());
ui.alarm.setOnSeekBarChangeListener({
onProgressChanged: function(seekbar, p, fromUser){
if(fromUser){
device.setAlarmVolume(p);
}
}
});
```