日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSVibrator開發(fā)指導(dǎo)

場景介紹

十余年品牌的成都網(wǎng)站建設(shè)公司,超過千家企業(yè)網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn).價(jià)格合理,可準(zhǔn)確把握網(wǎng)頁設(shè)計(jì)訴求.提供定制網(wǎng)站建設(shè)、購物商城網(wǎng)站建設(shè)、微信小程序響應(yīng)式網(wǎng)站開發(fā)等服務(wù),我們設(shè)計(jì)的作品屢獲殊榮,是您值得信賴的專業(yè)網(wǎng)站設(shè)計(jì)公司。

當(dāng)設(shè)備需要設(shè)置不同的振動(dòng)效果時(shí),可以調(diào)用 Vibrator 模塊,例如,設(shè)備的按鍵可以設(shè)置不同強(qiáng)度和時(shí)長的振動(dòng),鬧鐘和來電可以設(shè)置不同強(qiáng)度和時(shí)長的單次或周期性振動(dòng)。

接口說明

振動(dòng)器模塊主要提供的功能有:查詢設(shè)備上振動(dòng)器的列表,查詢某個(gè)振動(dòng)器是否支持某種振動(dòng)效果,觸發(fā)和關(guān)閉振動(dòng)器。VibratorAgent 類開放能力如下,具體請查閱 API 參考文檔。

接口名 描述
getVibratorIdList()獲取硬件設(shè)備上的振動(dòng)器列表。
isSupport(int)根據(jù)指定的振動(dòng)器Id查詢硬件設(shè)備是否存在該振動(dòng)器。
isEffectSupport(int, String)查詢指定的振動(dòng)器是否支持指定的震動(dòng)效果。
startOnce(int, String)對指定的振動(dòng)器創(chuàng)建指定效果的一次性振動(dòng)。
startOnce(String)對指定的振動(dòng)器創(chuàng)建指定效果的一次性振動(dòng)。
startOnce(int, int)對指定的振動(dòng)器創(chuàng)建指定振動(dòng)時(shí)長的一次性振動(dòng)。
startOnce(int)對指定的振動(dòng)器創(chuàng)建指定振動(dòng)時(shí)長的一次性振動(dòng)。
start(int, VibrationPattern)對指定的振動(dòng)器創(chuàng)建自定義效果的波形或一次性振動(dòng)。
start(VibrationPattern)對指定的振動(dòng)器創(chuàng)建自定義效果的波形或一次性振動(dòng)。
stop(int, String)關(guān)閉指定的振動(dòng)器指定模式的振動(dòng)。
stop(String)關(guān)閉指定的振動(dòng)器指定模式的振動(dòng)。

開發(fā)步驟

  1. 控制設(shè)備上的振動(dòng)器,需要在“config.json”里面進(jìn)行配置請求權(quán)限。具體如下:
   "reqPermissions": [
       {
           "name": "ohos.permission.VIBRATE",
           "reason": "",
           "usedScene": {
               "ability": [
                   ".MainAbility"
               ],
               "when": "inuse"
           }
       }
   ]

  1. 查詢硬件設(shè)備上的振動(dòng)器列表。
  1. 查詢指定的振動(dòng)器是否支持指定的震動(dòng)效果。
  1. 創(chuàng)建不同效果的振動(dòng)。
  1. 關(guān)閉指定的振動(dòng)器指定模式的振動(dòng)。
   private VibratorAgent vibratorAgent = new VibratorAgent();

    
   private int[] timing = {1000, 1000, 2000, 5000};

    
   private int[] intensity = {50, 100, 200, 255};

    
   @Override
   public void onStart(Intent intent) {
       super.onStart(intent);
       super.setUIContent(ResourceTable.Layout_vibrator_layout);

    
       // ...

    
       // 查詢硬件設(shè)備上的振動(dòng)器列表
       List vibratorList = vibratorAgent.getVibratorIdList();
       if (vibratorList.isEmpty()) {
           return;
       }
       int vibratorId = vibratorList.get(0);

    
       // 查詢指定的振動(dòng)器是否支持指定的振動(dòng)效果
       boolean isSupport = vibratorAgent.isEffectSupport(vibratorId,
               VibrationPattern.VIBRATOR_TPYE_CAMERA_CLICK);

    
       // 創(chuàng)建指定效果的一次性振動(dòng)
       boolean vibrateEffectResult = vibratorAgent.vibrate(vibratorId,
               VibrationPattern.VIBRATOR_TPYE_CAMERA_CLICK);

    
       // 創(chuàng)建指定振動(dòng)時(shí)長的一次性振動(dòng)
       int vibratorTiming = 1000;
       boolean vibrateResult = vibratorAgent.vibrate(vibratorId, vibratorTiming);

    
       // 創(chuàng)建自定義效果的周期性波形振動(dòng)
       int count = 5;
       VibrationPattern vibrationPeriodEffect = VibrationPattern.createPeriod(timing, intensity, count);
       boolean vibratePeriodResult = vibratorAgent.vibrate(vibratorId, vibrationPeriodEffect);

    
       // 創(chuàng)建自定義效果的一次性振動(dòng)
       VibrationPattern vibrationOnceEffect = VibrationPattern.createSingle(3000, 50);
       boolean vibrateSingleResult = vibratorAgent.vibrate(vibratorId, vibrationOnceEffect);

    
       // 關(guān)閉指定的振動(dòng)器自定義模式的振動(dòng)
       boolean stopResult = vibratorAgent.stop(vibratorId,
               VibratorAgent.VIBRATOR_STOP_MODE_CUSTOMIZED);
   }

新聞名稱:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSVibrator開發(fā)指導(dǎo)
網(wǎng)頁路徑:http://www.dlmjj.cn/article/djiooce.html