1 package ro
.ieval
.unical
;
3 import java
.io
.IOException
;
5 import android
.app
.Activity
;
6 import android
.content
.Context
;
7 import android
.media
.AudioManager
;
8 import android
.media
.MediaPlayer
;
9 import android
.media
.RingtoneManager
;
10 import android
.net
.Uri
;
11 import android
.os
.Bundle
;
12 import android
.view
.MotionEvent
;
13 import android
.view
.View
;
14 import android
.view
.View
.OnTouchListener
;
15 import android
.view
.Window
;
16 import android
.view
.WindowManager
;
17 import android
.widget
.Button
;
19 public class AlarmReceiverActivity
extends Activity
{
20 public static final String EXTRA_EVENT
= "event";
21 private MediaPlayer mMediaPlayer
;
24 public void onCreate(final Bundle savedInstanceState
) {
25 super.onCreate(savedInstanceState
);
26 this.requestWindowFeature(Window
.FEATURE_NO_TITLE
);
27 this.getWindow().setFlags(WindowManager
.LayoutParams
.FLAG_FULLSCREEN
, WindowManager
.LayoutParams
.FLAG_FULLSCREEN
);
28 setContentView(R
.layout
.alarm
);
30 final Button stopAlarm
= (Button
) findViewById(R
.id
.stopAlarm
);
31 stopAlarm
.setOnTouchListener(new OnTouchListener() {
33 public boolean onTouch(final View arg0
, final MotionEvent arg1
) {
40 playSound(this, getAlarmUri());
43 private void playSound(final Context context
, final Uri alert
) {
44 mMediaPlayer
= new MediaPlayer();
46 mMediaPlayer
.setDataSource(context
, alert
);
47 final AudioManager audioManager
= (AudioManager
) context
48 .getSystemService(Context
.AUDIO_SERVICE
);
49 if (audioManager
.getStreamVolume(AudioManager
.STREAM_ALARM
) != 0) {
50 mMediaPlayer
.setAudioStreamType(AudioManager
.STREAM_ALARM
);
51 mMediaPlayer
.prepare();
54 } catch (IOException e
) {
59 private static Uri
getAlarmUri() {
60 Uri alert
= RingtoneManager
.getDefaultUri(RingtoneManager
.TYPE_ALARM
);
62 alert
= RingtoneManager
.getDefaultUri(RingtoneManager
.TYPE_NOTIFICATION
);
64 alert
= RingtoneManager
.getDefaultUri(RingtoneManager
.TYPE_RINGTONE
);