【问题标题】:How to turn vibrate on and keep sound on as well如何打开振动并保持声音
【发布时间】:2013-01-28 09:07:44
【问题描述】:

由于AudioManager.RINGER_MODE_VIBRATE 也会使设备静音,您如何打开振动并保持当前音量(例如,如果有来电,手机会振动并播放铃声)?

谢谢!

【问题讨论】:

    标签: android audio vibration android-audiomanager


    【解决方案1】:

    我能想到的最简单的方法是使用:

    setVibrateSetting(AudioManagerVIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ON);
    

    虽然该方法在 API 16 中已被弃用,但如果您希望更改振动设置而不是您自己的应用程序,我不知道有什么好的替代方法。

    只要确保铃声模式也开启AudioManager.RINGER_MODE_NORMAL


    当然,您也可以将振铃模式设置为AudioManager.RINGER_MODE_NORMAL,然后调出设置页面供用户手动更改振动设置。

    【讨论】:

      【解决方案2】:

      查看此代码,

      // Get instance of Vibrator from current Context
              Vibrator vb = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
      
              // Start immediately
              // Vibrate for 200 milliseconds
              // Sleep for 500 milliseconds
              long[] pattern = { 0, 200, -1 };
      
              // The "0" means to repeat the pattern starting at the beginning
              // CUIDADO: If you start at the wrong index (e.g., 1) then your
              // pattern
              // will be off --
              // You will vibrate for your pause times and pause for your vibrate
              // times !
              vb.vibrate(pattern, 0);
      

      停下来,打电话

      vb.cancel();
      

      注意: 不应在 vb.vibrate(pattern, 0); 之后立即调用 vb.cancel();

      【讨论】:

      • 我不认为问题是“我现在如何让它振动?”
      猜你喜欢
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多