0

So I have an Alarm application which sets alarms. I have a very simple Service AlarmReceiver to get the alarm and do some action :

public class AlarmReceiver extends Service{

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onCreate() {
        // TODO Auto-generated method stub
        super.onCreate();
        MediaPlayer MPRadio1 = MediaPlayer.create(this, R.raw.radio3);
        MPRadio1.start();
        Toast.makeText(getBaseContext(), "Alarm received", Toast.LENGTH_LONG).show();           
    }

Now I'm wondering how would I be able to change the notification sound from another Activity so the AlarmReceiver service knows which sound should be played when alarm is received? So user can choose lets say, 3 sounds with radiobuttons and which he chooses AlarmReceiver knows which to play?

1 Answer 1

0

Store the user's preferences (the uris to the ringtones in your shared preferences) then when creating it use the value stored in the preferences to get the new value. You should always grab this value from the shared preferences when registering your alarm.

Note:

Also you should use SoundPool instead of a MediaPlayer AND you should also use Notifications they way they were intended, to be sent to the Notification bar via a PendingIntent. This notification sounds like your your actual activity is doing it, which is not how Notification tones should work.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.