@Override
public void onCreate() {
- mVibrator = new Vibrator();
+ mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// Listen for incoming calls to kill the alarm.
mTelephonyManager =
(TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Must reset the media player to clear the error state.
mMediaPlayer.reset();
setDataSourceFromResource(getResources(), mMediaPlayer,
- com.android.internal.R.raw.fallbackring);
+ R.raw.fallbackring);
startAlarm(mMediaPlayer);
} catch (Exception ex2) {
// At this point we just don't play anything.
private void startAlarm(MediaPlayer player)
throws java.io.IOException, IllegalArgumentException,
IllegalStateException {
- player.setAudioStreamType(AudioManager.STREAM_ALARM);
- player.setLooping(true);
- player.prepare();
- player.start();
+ final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
+ // do not play alarms if stream volume is 0
+ // (typically because ringer mode is silent).
+ if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) {
+ player.setAudioStreamType(AudioManager.STREAM_ALARM);
+ player.setLooping(true);
+ player.prepare();
+ player.start();
+ }
}
private void setDataSourceFromResource(Resources resources,
if (mPlaying) {
mPlaying = false;
+ Intent alarmDone = new Intent(Alarms.ALARM_DONE_ACTION);
+ sendBroadcast(alarmDone);
+
// Stop audio playing
if (mMediaPlayer != null) {
mMediaPlayer.stop();