Example usage for android.media RingtoneManager getDefaultUri

List of usage examples for android.media RingtoneManager getDefaultUri

Introduction

In this page you can find the example usage for android.media RingtoneManager getDefaultUri.

Prototype

public static Uri getDefaultUri(int type) 

Source Link

Document

Returns the Uri for the default ringtone of a particular type.

Usage

From source file:com.licenta.android.licenseapp.SchedulingService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intentDismiss = new Intent(this, MainTabActivity.class);
    intentDismiss.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.ALARM_ID);
    intentDismiss.putExtra(Constants.KEY_DISMISS_ALARM, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentDismiss,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("HellO")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setCategory(Notification.CATEGORY_ALARM).setSound(alarmSound);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    mBuilder.setSound(Uri.parse(prefs.getString("alarm_ringtone", "")));
    if (prefs.getBoolean("alarm_vibrate", false))
        mBuilder.setVibrate(new long[] { 1000, 1000 });

    mBuilder.addAction(0, getString(R.string.check_in), pendingIntent);
    mBuilder.addAction(R.drawable.ic_stat_action_alarm_off_notif, getString(R.string.dismiss_alarm),
            pendingIntent);//from w ww.  ja  va2 s  .  c o m
    //mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build());
}

From source file:com.fjoglar.etsitnoticias.view.notification.Notification.java

public static void createNotification(Context context) {
    if (needToNotify()) {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);

        if (mNewsCount == 1) {
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            bigTextStyle.bigText(mNotificationDesc.get(0))
                    .setSummaryText(context.getResources().getString(R.string.app_name));

            // Create the notification.
            mBuilder.setSmallIcon(R.drawable.ic_notification).setContentTitle(mNotificationText.get(0))
                    .setContentText(mNotificationDesc.get(0))
                    .setColor(context.getResources().getColor(R.color.colorPrimary))
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setAutoCancel(true).setStyle(bigTextStyle);
        } else {/*w w  w .j  a  v  a  2 s .co m*/
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(context.getResources().getString(R.string.app_name));
            inboxStyle.setSummaryText("Tienes " + mNewsCount + " noticias nuevas.");
            for (String notificationTxt : mNotificationText) {
                inboxStyle.addLine(notificationTxt);
            }

            // Create the notification.
            mBuilder.setSmallIcon(R.drawable.ic_notification)
                    .setContentTitle(context.getResources().getString(R.string.app_name))
                    .setContentText("Tienes " + mNewsCount + " noticias nuevas.")
                    .setColor(context.getResources().getColor(R.color.colorPrimary))
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setAutoCancel(true).setStyle(inboxStyle);
        }

        Intent resultIntent = new Intent(context, NewsListActivity.class);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(ETSIT_NEWS_NOTIFICATION_ID, mBuilder.build());
    }

    // Clear values for next notifications.
    mNewsCount = 0;
    mNotificationText.clear();
}

From source file:com.contactlab.clabpush_android_sample.GcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_template_icon_bg).setContentTitle("GCM Message")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.pg.app.gcm.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_icon_info).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.github.piasy.taskdemo.NotificationUtil.java

private static NotificationCompat.Builder getCommonBuilder(Context context) {
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    long[] pattern = { 500, 500, 500, 500 };
    return new NotificationCompat.Builder(context).setSmallIcon(R.mipmap.ic_launcher).setSound(alarmSound)
            .setVibrate(pattern).setLights(Color.BLUE, 500, 500).setAutoCancel(true);
}

From source file:com.onsemi.matrix.android.pushnotification.PNGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("GCM Message")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.sqldexter.gcmnetworking.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setColor(Color.parseColor("#e65100")).setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("GCM Message").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.votzapp.app.MyGcmListenerService.java

/**
 * Called when message is received./*from ww  w.j a  v  a2 s  .  c om*/
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
//And show mobile notification
@Override
public void onMessageReceived(String from, Bundle data) {
    String body = data.getString("body");
    String title = data.getString("title");

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(body)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);
    notificationManager.notify(1, mBuilder.build());

}

From source file:com.ce.skuniv.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();//from   ww  w  .  ja  v  a  2s .  com
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    //      mNotificationManager.notify(Id, mBuilder.build());
}

From source file:com.ezio.multiwii.helpers.Notifications.java

public void displayNotification(String title, String text, boolean Sound, int Id, boolean isPresistant) {
    if (Id == 0) {
        Id = rnd.nextInt();//from  ww  w  .ja va 2 s. c o  m
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_stat_icon).setContentTitle(title).setContentText(text);
    if (Sound)
        mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // mBuilder.setOnlyAlertOnce(false);
    mBuilder.setTicker(title + ":" + text);
    mBuilder.setOngoing(isPresistant);
    mBuilder.setAutoCancel(true);

    // Intent notificationIntent = new Intent(context,
    // MainMultiWiiActivity.class);

    Intent notificationIntent = new Intent(context, MainMultiWiiActivity.class);
    // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You
    // need this if starting
    // the activity from a service
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);

    mNotificationManager.notify(Id, mBuilder.build());
}