HarmonyOS鸿蒙Next中畅享50和UAWEI WATCH 3应用振动强度调节函数vibrationPattern.setIntensity()无效
HarmonyOS鸿蒙Next中畅享50和UAWEI WATCH 3应用振动强度调节函数vibrationPattern.setIntensity()无效 我在尝试开发华为畅享50和HUAWEI WATCH 3手表的震动功能的时候,发现振动强度无法调节。是设备本身不支持振动大小的调节,还是我的代码有问题?
UI界面使用的XML:
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="600px"
ohos:orientation="vertical"
ohos:padding="32">
<Text
ohos:id="$+id:text"
ohos:width="match_content"
ohos:height="match_content"
ohos:layout_alignment="horizontal_center"
ohos:text="Button."
ohos:text_size="15fp"/>
<Button
ohos:id="$+id:button1"
ohos:margin="50"
ohos:width="match_content"
ohos:height="match_content"
ohos:layout_alignment="horizontal_center"
ohos:text="My name is Button."
ohos:text_size="50"/>
<Slider
ohos:id="$+id:slider"
ohos:width="400px"
ohos:max="255"
ohos:min="0"/>
<Button
ohos:id="$+id:button2"
ohos:margin="50"
ohos:width="match_content"
ohos:height="match_content"
ohos:layout_alignment="horizontal_center"
ohos:text="Stop."
ohos:text_size="50"/>
</DirectionalLayout>
使用MainAbility调用振动函数,大概功能是点击一下上面的按钮开始振动,点击下面的按钮振动停止,中间的滑条用来调整振动强度大小。
package com.example.learn_13;
import com.example.learn_13.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Slider;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.vibrator.agent.VibratorAgent;
import ohos.vibrator.bean.VibrationPattern;
import java.util.List;
public class MainAbility extends Ability {
private VibratorAgent vibratorAgent = new VibratorAgent();
private int[] timing = {1000, 1000, 2000, 5000};
private int[] intensity = {0, 100, 200, 255};
private VibrationPattern vibrationPattern = VibrationPattern.createSingle(10000,0);
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_vibrator_layout);
Button button1 = (Button) findComponentById(ResourceTable.Id_button1);
Button button2 = (Button) findComponentById(ResourceTable.Id_button2);
Text text = (Text) findComponentById(ResourceTable.Id_text);
Slider slider = (Slider) findComponentById(ResourceTable.Id_slider);
slider.setProgressValue(0);
List<Integer> vibratorList = vibratorAgent.getVibratorIdList();
if (vibratorList.isEmpty()) {
if (text != null)
{
text.setText("Empty.");
}
return;
}
int vibratorId = vibratorList.get(0);
if (button1 != null) {
ShapeElement background = new ShapeElement();
background.setRgbColor(new RgbColor(0, 125, 255));
background.setCornerRadius(25);
button1.setBackground(background);
button1.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
vibratorAgent.start(vibratorId, vibrationPattern);
button1.setText("Click.");
}
});
}
if (button2 != null){
ShapeElement background = new ShapeElement();
background.setRgbColor(new RgbColor(0, 125, 255));
background.setCornerRadius(25);
button2.setBackground(background);
button2.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
vibratorAgent.stop();
}
});
}
if (slider != null){
slider.setValueChangedListener(new Slider.ValueChangedListener() {
@Override
public void onTouchStart(Slider slider)
{
}
@Override
public void onProgressUpdated(Slider slider, int progress, boolean fromUser)
{
vibratorAgent.stop();
vibrationPattern.setIntensity(progress);
text.setText(String.valueOf(vibrationPattern.getIntensity()));
vibratorAgent.start(vibratorId, vibrationPattern);
}
@Override
public void onTouchEnd(Slider slider)
{
}
});
}
}
}
目前设备可以振动,但是强度无法变化。就算把代码改成VibrationPattern.createPeriod(timing,intensity,3)创建振动模式振动强度也不变,无论强度如何设置。
有没有大佬解答一下?谢谢!
更多关于HarmonyOS鸿蒙Next中畅享50和UAWEI WATCH 3应用振动强度调节函数vibrationPattern.setIntensity()无效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
您好,您的问题需要进一步定位,请您通过在线提单进一步解决:https://developer.huawei.com/consumer/cn/support/feedback/,感谢您的反馈和支持。
更多关于HarmonyOS鸿蒙Next中畅享50和UAWEI WATCH 3应用振动强度调节函数vibrationPattern.setIntensity()无效的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
已经提交了,谢谢!
在HarmonyOS鸿蒙Next中,vibrationPattern.setIntensity()
函数用于设置振动强度,但在畅享50和HUAWEI WATCH 3上可能无效。这可能与设备的硬件限制或系统版本有关。不同设备对振动的支持程度不同,某些设备可能不支持动态调整振动强度。此外,系统版本或API的差异也可能导致该函数在某些设备上无法正常工作。建议检查设备的硬件规格和系统版本,确认是否支持该功能。
在HarmonyOS鸿蒙Next中,vibrationPattern.setIntensity()
函数用于设置振动强度,但在畅享50和HUAWEI WATCH 3上可能无效。这可能是由于设备硬件限制或系统版本不兼容。建议检查设备是否支持该功能,并确保系统已更新至最新版本。如果问题依旧,可以尝试使用其他振动API或联系华为技术支持获取进一步帮助。