play Notification Sound - Android Android OS

Android examples for Android OS:Notification

Description

play Notification Sound

Demo Code


//package com.java2s;

import android.content.Context;

import android.media.AudioManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;

public class Main {
    public static void playNotificationSound(Context context) {
        Uri uri = RingtoneManager//from   w ww.  jav  a 2  s  . co  m
                .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (uri != null) {
            Ringtone rt = RingtoneManager.getRingtone(context, uri);
            if (rt != null) {
                rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
                rt.play();
            }
        }
    }
}

Related Tutorials