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.perfilyev.vkmessengerlite.MessagingService.java

NotificationCompat.Builder provideBuilder(long peerId) {
    PendingIntent contentIntent = createPendingIntent();

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    List<ChatItem.NotificationInfoPeer> notificationInfoList = database
            .createQuery(ChatItem.TABLE_NAME, ChatItem.NOTIFICATION_FOR_PEER, String.valueOf(peerId))
            .mapToList(ChatItem.NOTIFICATION_INFO_PEER_ROW_MAPPER::map).toBlocking().first();

    NotificationCompat.MessagingStyle style = new NotificationCompat.MessagingStyle(USER_DISPLAY_NAME);

    String groupKey = null;/*from  w  w w  . j av  a 2s  .  c  om*/
    int count = 0;

    for (ChatItem.NotificationInfoPeer notificationInfo : notificationInfoList) {
        style.addMessage(notificationInfo.body(), notificationInfo.date(), notificationInfo.fullName());
        if (groupKey == null) {
            groupKey = notificationInfo.fullName();
        }
        if (peerId > 2000000000) {
            style.setConversationTitle(notificationInfo.peerName());
            groupKey = notificationInfo.peerName();
        }
        count++;
    }
    NotificationCompat.Action replyAction = createReplyAction(peerId, contentIntent);

    NotificationCompat.Builder builder = createBuilder(defaultSoundUri, contentIntent);
    return builder.setStyle(style).addAction(replyAction).setGroup(groupKey).setGroupSummary(true)
            .setSubText(String.format(Locale.getDefault(), "Unread: %s", count));
}

From source file:com.nicolacimmino.expensestracker.tracker.data_sync.GcmIntentService.java

private void showExpensesUpdatedNotification() {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, ExpensesListActivity.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getResources().getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(getResources().getString(R.string.notification_data_changed)))
            .setContentText(getResources().getString(R.string.notification_data_changed)).setAutoCancel(true)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLights(Color.rgb(219, 70, 0), 700, 1000).setOnlyAlertOnce(true);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(EXPENSES_UPDATED_NOTIFICATION_ID, mBuilder.build());
}

From source file:com.phonegap.Notification.java

/**
 * Beep plays the default notification ringtone.
 * //w ww. j a v a2  s. c o m
 * @param count         Number of times to play notification
 */
public void beep(long count) {
    Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);

    // If phone is not set to silent mode
    if (notification != null) {
        for (long i = 0; i < count; ++i) {
            notification.play();
            long timeout = 5000;
            while (notification.isPlaying() && (timeout > 0)) {
                timeout = timeout - 100;
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
        }
    }
}

From source file:com.apps.howard.vicissitude.services.NotificationService.java

private Uri getAlarmTone() {
    return Uri.parse(prefs.getString(getString(R.string.pref_sound_alarm_tone_key),

            RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM).toString()));
}

From source file:com.example.petri.myapplication.GCMMessageListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//ww  w . j  a v a2s.  co  m
 */
private void sendNotification(String message, int from_id) {
    Intent intent = new Intent(this, ChatActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("chat_id", from_id);
    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_icon).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.botree.botree911_client.notification.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  ww w.  j ava  2  s  .c  o  m*/
private void sendNotification(String title, String messageBody) {
    int count = PreferenceUtility.getNoticationCount(MyFirebaseMessagingService.this);
    PreferenceUtility.saveNotificationCount(MyFirebaseMessagingService.this, (count + 1));
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title);
    bigTextStyle.bigText(messageBody);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setSmallIcon(R.drawable.ic_stat_name);
        notificationBuilder.setColor(ResourcesCompat.getColor(getResources(), R.color.colorGreenLight, null));
    } else {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
    }

    notificationBuilder.setContentTitle(title);
    notificationBuilder.setContentText(messageBody);
    notificationBuilder.setStyle(bigTextStyle);
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setSound(defaultSoundUri);
    notificationBuilder.setContentIntent(pendingIntent);

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

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

From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  ww w  .  ja va2  s. c om
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, GpsMainActivity.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.circle_green).setContentTitle(getString(R.string.gcmClientGcmMsg))
            .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.neatier.shell.notification.FCMListenerService.java

/**
 * Create and show a simple notification containing the received FCM remoteMessage.
 *
 * @param remoteMessage FCM remoteMessage body received.
 *///from ww w. ja  v  a2  s  . c om
private void sendNotification(RemoteMessage remoteMessage) {
    RemoteMessage.Notification noti = remoteMessage.getNotification();
    KeyValuePairs<String, String> data = new KeyValuePairs<>();

    String title = getString(R.string.app_name);
    String message = getString(R.string.fcm_message_default);
    StringBuffer contentText = new StringBuffer();
    if (noti != null) {
        title = TextUtils.isEmpty(noti.getTitle()) ? getString(R.string.app_name) : noti.getTitle();
        contentText.append(
                TextUtils.isEmpty(noti.getBody()) ? getString(R.string.fcm_message_default) : noti.getBody());
    }
    if (remoteMessage.getData() != null) {
        data.putAll(remoteMessage.getData());
        title = data.getOrDefault("title", getString(R.string.app_name));
        contentText.append(data.getOrDefault("message", getString(R.string.fcm_message_default)));
    }
    Context context = this;
    Intent intent = new Intent(this, NotificationActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = (int) (System.currentTimeMillis() & 0xfffffff);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack
    //stackBuilder.addParentStack(NotificationActivity.class);
    stackBuilder.addNextIntentWithParentStack(new Intent(context, MainActivity.class));
    stackBuilder.addNextIntent(intent);
    // Adds the Intent to the top of the stack
    //stackBuilder.addNextIntent(intent);
    // Gets a PendingIntent containing the entire back stack
    //Need to set PendingIntent.FLAG_UPDATE_CURRENT to work with the starting intent.
    //See issue: http://goo.gl/lJrMNg
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //PendingIntent resultPendingIntent =
    //      stackBuilder.getPendingIntent(requestCode, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_neat_logo).setContentTitle(title).setContentText(contentText.toString())
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(resultPendingIntent)
            .setDefaults(Notification.DEFAULT_VIBRATE);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(requestCode, notificationBuilder.build());
}

From source file:com.clanofthecloud.cotcpushnotifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w  w  w.  ja v  a 2 s.  c om*/
 */
private void sendNotification(String message) {
    Activity currentAct = UnityPlayer.currentActivity;
    Class activityToOpen = currentAct != null ? currentAct.getClass() : UnityPlayerActivity.class;
    Intent intent = new Intent(this, activityToOpen);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        int notificationIcon = ai.metaData.getInt("cotc.GcmNotificationIcon", -1);
        if (notificationIcon == -1) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationIcon not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }
        int notificationLargeIcon = ai.metaData.getInt("cotc.GcmNotificationLargeIcon", -1);
        if (notificationLargeIcon == -1) {
            Log.e(TAG, "There is no large icon for push notifs, will only use default icon");
            return;
        }

        String pushNotifName = ai.metaData.getString("cotc.GcmNotificationTitle");
        if (pushNotifName == null) {
            Log.e(TAG,
                    "!!!!!!!!! cotc.GcmNotificationTitle not configured in manifest, push notifications won't work !!!!!!!!!");
            return;
        }

        if (notifManager == null)
            notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel channel = new NotificationChannel("CotC Channel", "CotC Channel", importance);
            channel.setDescription("CotC Channel");
            notifManager.createNotificationChannel(channel);
            notificationBuilder = new NotificationCompat.Builder(this, "CotC Channel");
        } else
            notificationBuilder = new NotificationCompat.Builder(this);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        notificationBuilder.setSmallIcon(notificationIcon).setContentTitle(pushNotifName)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent).setPriority(Notification.PRIORITY_HIGH);
        if (notificationLargeIcon != -1)
            notificationBuilder.setLargeIcon(
                    BitmapFactory.decodeResource(currentAct.getResources(), notificationLargeIcon));

        notifManager.notify(0 /* ID of notification */, notificationBuilder.build());
    } catch (Exception e) {
        Log.w(TAG, "Failed to handle push notification", e);
    }
}

From source file:com.footprint.cordova.plugin.localnotification.Options.java

/**
 * Returns the path of the notification's sound file
 *//*from   w w  w  .j  av  a  2  s .c o m*/
public Uri getSound() {
    String sound = options.optString("sound", null);

    if (sound != null) {
        try {
            int soundId = (Integer) RingtoneManager.class.getDeclaredField(sound).get(Integer.class);

            return RingtoneManager.getDefaultUri(soundId);
        } catch (Exception e) {
            return Uri.parse(sound);
        }
    }

    return null;
}