Getter for the current Default Notification Ringtone object. - Android Android OS

Android examples for Android OS:Notification

Description

Getter for the current Default Notification Ringtone object.

Demo Code


//package com.java2s;
import android.content.Context;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;

public class Main {
    /**/*from  ww  w  . ja  va2  s. c om*/
     * Getter for the current Default Notification Ringtone object.
     * @param ctx
     * @return The Ringtone, or null if there isn't one set.
     */
    public static Ringtone getDefaultNotificationRingtone(Context ctx) {
        Uri currentNotificationRingtoneUri = getDefaultNotificationRingtoneUri(ctx);

        if (currentNotificationRingtoneUri == null) {
            return null;
        }

        Ringtone r = RingtoneManager.getRingtone(ctx,
                currentNotificationRingtoneUri);

        return r;
    }

    /**
     * Getter for the current Default Notification Ringtone URI.
     * @param ctx
     * @return
     */
    public static Uri getDefaultNotificationRingtoneUri(Context ctx) {
        return RingtoneManager.getActualDefaultRingtoneUri(ctx,
                RingtoneManager.TYPE_NOTIFICATION);
    }
}

Related Tutorials