私のアプリでは、サービスから着信音を再生しています。
protected boolean playRingtone() {
Uri ringtoneUri = _savedValues.loadRingtoneUri();
_audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
_maxVolume = _audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
_oldVolume = _audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
_audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, _maxVolume,AudioManager.FLAG_SHOW_UI);
_mp = new MediaPlayer();
try {
_mp.setDataSource(this, ringtoneUri);
} catch (Exception e) {
return false;
}
_mp.setVolume(_maxVolume, _maxVolume);
_mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
_mp.setLooping(true);
try {
_mp.prepare();
} catch (Exception e) {
return false;
}
_mp.start();
return true;
}
そしてサービス停止時
public void Stop() {
//cancel ringtone playback if it's going on
if (_ringAloud) {
if (_audioManager != null) {
_audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,_oldVolume, AudioManager.FLAG_SHOW_UI);
}
if (_mp != null) {
if (_mp.isPlaying()) {
_mp.stop();
}
_mp.release();
}
}
さて、サービスが停止するまで振動させたいです。ただし、Vibrator クラスには vibrate(time) と vibrate(pattern,repeat) 以外のメソッドはありません。それで、着信音と同期して電話を振動させる方法はありますか。