Example usage for android.media Ringtone play

List of usage examples for android.media Ringtone play

Introduction

In this page you can find the example usage for android.media Ringtone play.

Prototype

public void play() 

Source Link

Document

Plays the ringtone.

Usage

From source file:Main.java

public static void playDefault(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
}

From source file:Main.java

public static void playDefaultNotificationSound(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
}

From source file:Main.java

public static void playSound(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
}

From source file:Main.java

public static void playNotification(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
}

From source file:Main.java

public static void ring(Context context) {
    if ((System.currentTimeMillis() - beepTime) > 6 * 1000) {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(context.getApplicationContext(), notification);
        r.play();
        beepTime = System.currentTimeMillis();
    } else {//from w  w  w .  jav  a  2  s. c o  m
        beepTime = 0;
    }

}

From source file:Main.java

public static void playNotificationSound(Context context) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    if (uri != null) {
        Ringtone rt = RingtoneManager.getRingtone(context, uri);
        if (rt != null) {
            rt.setStreamType(AudioManager.STREAM_NOTIFICATION);
            rt.play();
        }/*from  w w w  . j  av  a 2 s.c om*/
    }
}

From source file:com.cfc.needblood.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  w  w w .j a v a 2 s.  c  o m
private static void generateNotification(Context context, String message) {
    long when = System.currentTimeMillis();

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Change the icons to conform Android's design guildeline
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bd_icon))
            .setTicker(message).setWhen(when).setAutoCancel(true)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.notification_message));

    Notification notification = builder.build();

    notificationManager.notify(0, notification);

    // Notification sound, comment out if do not need
    Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, ringtone);
    r.play();
}

From source file:eu.geopaparazzi.library.util.Utilities.java

/**
 * Ring action./*from  w  w  w  .  j av a  2  s . co m*/
 *
 * @param context if something goes wrong.
 */
public static void ring(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();

}

From source file:com.gm.goldencity.util.Utils.java

/**
 * Play notification sound// w  ww  . j  a  v  a2  s .  c om
 *
 * @param context Application context
 */
public static void playNotificationSound(Context context) {
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone r = RingtoneManager.getRingtone(context, notification);
    r.play();
}

From source file:MainActivity.java

public void clickSound(View view) {
    Uri notificationSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), notificationSoundUri);
    ringtone.play();
}