捕获 SDK 请求电池电量不起作用



需要有关新的 Android 捕获 SDK 的帮助。我在活动上使用以下代码。

Capture.builder(getApplicationContext())
.enableLogging(BuildConfig.DEBUG)
.appKey(appKey)
.build();
captureClient = new CaptureClient(appKey);
captureClient.setListener(this);
captureClient.connect(connectionCallback);

我正在顶级活动中使用带有 appid 的正确应用密钥。

我想请求电池电量。我该怎么做? 我已经实现了一个侦听器,但不确定如何发出请求。

好的,接下来我有这个作为请求:

if (mDevice != null) {
mDevice.getBatteryLevel(propertyCallback);
}
PropertyCallback propertyCallback = new PropertyCallback() {
@Override
public void onComplete(@Nullable CaptureError captureError, @Nullable Property property) {
if (captureError != null) {
Log.d("onComplete", String.format("capture error %s", captureError.getMessage()));
} else {
if (property != null) {
Log.d("onComplete", String.format("property set %d", property.getId()));
Preference socketCharge = (Preference) findPreference("bt_scanner_battery_charge");
if (socketCharge != null) {
try {
int i = property.getInt();
socketCharge.setSummary(String.format("Current charge level: %d%%", i));
} catch (Exception e) {
Log.e("SocketChargeError", "" + e.getMessage());
}
}
}
}
}
};

上面的代码执行往返并调用属性回调,但属性中包含的信息不是百分比。

这是侦听器(从不调用),即使我的类实现了它并订阅了"事物"。

@Override public void onBatteryLevelChanged(int i) {

好的,在与 Socket Mobile 的支持人员交谈后,一位软件工程师告诉我如何将电池电量信息打包到属性响应中。 在这里。。。现在只需格式化它即可显示!

Code:
int value = property.getInt();
int current = value >>> 8 & 0xFF;
int min = value >>> 16 & 0xFF;
int max = value >>> 24 & 0xFF;
Double batteryPercent = current * 100.0 / (max - min);

相关内容

最新更新