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.example.yongwoon.sendbirdtest.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */// w w  w.j  ava 2s .  co m
public static void sendNotification(Context context, String messageBody, String channelUrl) {
    Intent intent = MainActivity_.intent(context).get();
    intent.putExtra("groupChannelUrl", channelUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 1 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setPriority(Notification.PRIORITY_MAX)
            .setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);

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

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

From source file:com.aluvi.android.services.push.AluviPushNotificationListenerService.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.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.licenta.android.licenseapp.location.GeofenceTransitionsService.java

private void sendNotification(String msg) {
    NotificationManager 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);/*  w  w w  . j av a 2 s. co  m*/
    //mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build());
}

From source file:com.cardillsports.vithushan.cardillsportsandroid.service.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from   w w w.  ja  v a2s .co m
private void sendNotification(String messageBody) {
    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.cslogo).setContentTitle("FCM Message").setContentText(messageBody)
            .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.shivaraj.friendz.shivaraj.CloudMessaging.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from   www  .j ava2s  .c  o  m
private void sendNotification(String messageBody) {
    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.mipmap.ic_launcher).setContentTitle("pokemon").setContentText(messageBody)
            .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.digium.respoke.GcmIntentService.java

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

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ConnectActivity.class),
            0);/*from  w ww  .  j  a v a2  s .  c om*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Respoke")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(alarmSound);

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

From source file:com.bayapps.android.robophish.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 */// w ww.  j  a v  a 2s  .  c o m
private void showNotification(String title, String subtitle, String mediaId) {
    Intent intent = new Intent(this, MusicPlayerActivity.class);
    intent.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, false);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    //TEST
    intent.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    intent.putExtra("title", title);
    intent.putExtra("subtitle", subtitle);
    intent.putExtra("showid", "__TRACKS_BY_SHOW__/" + mediaId);

    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_allmusic_black_24dp).setContentTitle("There's a new Phish show!")
            .setContentText(title + ", " + subtitle).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(Integer.parseInt(mediaId), notificationBuilder.build());
}

From source file:com.uriel.myapplication.MyGcmListenerService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void showNotification(String mssg) {

    // define sound URI, the sound to be played when there's a notification
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    // intent triggered, you can add other intent for other actions
    Intent intent2 = new Intent(this, MainActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent2, 0);

    // this is it, we'll build the notification!
    // in the addAction method, if you don't want any icon, just set the first param to 0

    Notification mNotification = new NotificationCompat.Builder(this)
            .setContentTitle("International School of Monaco").setContentText(mssg).setAutoCancel(true)
            .setContentIntent(pIntent).setSound(soundUri).setSmallIcon(R.mipmap.ic_launcher) //ok
            // .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            // .addAction(0, "View", pIntent)
            // .addAction(0, "Remind", pIntent)
            .build();//from   w  ww.  j  a v  a2  s.co  m

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // If you want to hide the notification after it was selected, do the code below
    // myNotification.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, mNotification);

}

From source file:br.com.awa.mylottery.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w ww . j a va2  s  .  c  o m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, HomeActivity.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.common_ic_googleplayservices).setContentTitle("MyLottery")
            .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.pixtory.app.pushnotification.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from w  w  w  . j a  v a2s  . com*/
 */
private void sendNotification(String message, String image) {
    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Bitmap b = null;
    try {
        URL url = new URL(image);
        b = BitmapFactory.decodeStream(url.openConnection().getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.notif).setContentTitle("pixtory").setContentText(message)
            .setAutoCancel(true);

    //.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.pixtory))
    if (b != null)
        notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(b));

    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    AmplitudeLog.logEvent(new AmplitudeLog.AppEventBuilder(App_Notification_Shown)
            .put(AppConstants.USER_ID, Utils.getUserId(getApplicationContext())).build());
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}