krishnansuccess / droid-notify

Automatically exported from code.google.com/p/droid-notify
0 stars 0 forks source link

Please add selection of sound ringtones #185

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently I am not found how to change sound o fnotification in application - I 
could change it on system level but it is not want I want.

The second thing is that will be nice to allow user choose ring tone instead 
notification - it has some nice side effect that generate reapeating sound till 
user will click and has much nicer sound than notification. Ringtone lopping 
could be stoped with some trick - whatever I prefer looping ring tone  TILL 
TOUCH.

Some code example maybe will be usefull.

                AudioManager audioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
                final int volume = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(view.getContext());
                Uri notificationSoundUri = Uri.parse(prefs.getString("notification_sound", "DEFAULT_SOUND"));

                MediaPlayer mediaPlayer = new MediaPlayer();
                // clean if it is not loopping
                mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mediaPlayer) {
                        mediaPlayer.release();
                    }
                });
                // async prepare
                mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                    @Override
                    public void onPrepared(MediaPlayer mediaPlayer) {
                        mediaPlayer.setVolume(volume, volume);
                        mediaPlayer.start();
                    }
                });
                // stop after first loop
                mediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {

                    @Override
                    public void onSeekComplete(MediaPlayer mediaPlayer) {
                        // TODO Auto-generated method stub
                        mediaPlayer.stop();
                        mediaPlayer.release();
                    }
                });

                try {
                    mediaPlayer.setDataSource(view.getContext(), notificationSoundUri);
                } catch (Exception e1) {
                    e1.printStackTrace();
                    mediaPlayer.release();
                    return;
                }
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
                try {
                    mediaPlayer.prepareAsync();
                } catch (Exception e1) {
                    e1.printStackTrace();
                    mediaPlayer.release();
                    return;
                }
            }

Original issue reported on code.google.com by Cezary.W...@gmail.com on 28 Jan 2013 at 11:49

GoogleCodeExporter commented 9 years ago
The current sound in the notifications is sufficient. Feel free to extend the 
project with this suggestion. Thanks for the support :)

Original comment by cs3vi...@gmail.com on 10 Mar 2013 at 2:54

GoogleCodeExporter commented 9 years ago
As you wish you could do what you want :)

Original comment by Cezary.W...@gmail.com on 12 Mar 2013 at 12:06