2016-11-09 46 views

回答

2

检查状态和做

AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); 
    if (am.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { 
     Toast.makeText(this, "cannot vibrate already muted", Toast.LENGTH_SHORT).show(); 
    } else { 
     Vibrator vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); 
     vibrator.vibrate(2000); 
     Toast.makeText(this, "I'm running", Toast.LENGTH_SHORT).show(); 
    } 
+0

我知道这个解决方案,但我的观点所需的工作是,有没有可能让它自动停止振动,我的意思是它只是将用户的设置和即使我称之为“振动”,如果他不振动,也会停止振动 – ammcom

相关问题