当我的应用 运行 时拒绝振动(我的应用除外)

Deny vibrations (except my app) while my app is running

我想为盲人创建一个 android 应用程序,所以我 不希望 在我的应用程序之外 振动 ],比如通知或其他应用程序,否则它们会改变模式。我如何使用 Java 以编程方式完成此操作?

正如 SteelToe 所说:

Just set the ringer to silence when your app is running and then turn the ringer back on to vibrate right before your app vibrates and then after it vibrates put it back on scilence

因此您可以使用如下代码:

function vibrateOn(){
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
            AudioManager.VIBRATE_SETTING_ON);
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
            AudioManager.VIBRATE_SETTING_ON);
}

function vibrateOff(){
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
            AudioManager.VIBRATE_SETTING_OFF);
    audio.setVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION,
            AudioManager.VIBRATE_SETTING_OFF);
}

这是所有选项。

switch (position) {
 case 0:
    audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
       break;
 case 1:
     audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
       break;
case 2:
     audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
      audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
         AudioManager.VIBRATE_SETTING_OFF);
       break;
 case 3:
    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, 
        AudioManager.VIBRATE_SETTING_ON);
    break;
 }