Back to project page MyLibReminder.
The source code is released under:
Apache License
If you think the Android project MyLibReminder listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.geonnave.mylibreminder; /*from ww w. j a v a 2 s . c o m*/ import java.io.IOException; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; public class AlarmReceiverActivity extends Activity { private MediaPlayer mMediaPlayer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.loan_alarm); Button stopAlarm = (Button) findViewById(R.id.stopAlarm); stopAlarm.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mMediaPlayer.stop(); finish(); } }); playSound(this, getAlarmUri()); } private void playSound(Context context, Uri alert) { mMediaPlayer = new MediaPlayer(); try { mMediaPlayer.setDataSource(context, alert); final AudioManager audioManager = (AudioManager) context .getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0) { mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mMediaPlayer.prepare(); mMediaPlayer.start(); } } catch (IOException e) { System.out.println("OOPS"); } } //Get an alarm sound. Try for an alarm. If none set, try notification, //Otherwise, ringtone. private Uri getAlarmUri() { Uri alert = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_ALARM); if (alert == null) { alert = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_RINGTONE); } } return alert; } }