I figured out a way to do this. This is a stripped down version (no
error checking, etc.).

I set the default ringtone and notification to my preferred values
from out of the standard set that comes with my N-1. Then, I make sure
that the volume is set to the maximum on ringtones, notifications,
alarms, etc. While I'm at it, I make sure that vibrate is turned on.

Now, all I have to do is set it up to run via the reboot plugin for
the "Locale" app. I'll post another message after I try that.

Here's the code:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // The RingtoneManager cursor doesn't work (why?), so instead
of
        // traversing the list of ringtones and selecting the ones I
want by title,
        // I just hard-code the pathnames here.
        Uri ruri = Uri.parse("file:///system/media/audio/ringtones/
Ring_Digital_02.ogg");
        Uri nuri = Uri.parse("file:///system/media/audio/notifications/
F1_New_MMS.ogg");
        try {
            RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_RINGTONE, ruri);
        }
        catch (Throwable t) {
            // error handling goes here -- also, use something other
than Throwable
        }
        try {
            RingtoneManager.setActualDefaultRingtoneUri(this,
RingtoneManager.TYPE_NOTIFICATION, nuri);
        }
        catch (Throwable t) {
            // error handling goes here -- also, use something other
than Throwable
        }
        AudioManager audio = (AudioManager)
getSystemService(Context.AUDIO_SERVICE);
        audio.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        for (int volumeType: (new int[] { AudioManager.STREAM_SYSTEM,
                                          AudioManager.STREAM_RING,
 
AudioManager.STREAM_NOTIFICATION,
 
AudioManager.STREAM_ALARM })) {
            int maxVolume = audio.getStreamMaxVolume(volumeType);
            audio.setStreamVolume(volumeType, maxVolume,
AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE);
            audio.setStreamMute(volumeType, false);
            audio.setVibrateSetting(volumeType,
AudioManager.VIBRATE_SETTING_ON);
        }
        this.finish();
    }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to