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:crea.wallet.lite.service.CreativeCoinService.java

private void notifyCoinsReceived(Sha256Hash hash) {
    if (!Configuration.getInstance().isNotificationsEnabled()) {
        return;/*from   www  . j a  va  2  s . c o  m*/
    }

    int notificationCount = transactionsReceived.size();
    if (notificationCount == 1) {
        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    }

    notificationAccumulatedAmount = Coin.ZERO;
    for (Coin c : transactionsReceived.values()) {
        notificationAccumulatedAmount = notificationAccumulatedAmount.add(c);
    }

    Coin coin = Coin.valueOf(notificationAccumulatedAmount.getValue());
    String msg;
    Intent intent;

    msg = getString(R.string.notif_accumulated_amount, coin.toFriendlyString(), notificationCount);
    intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    intent.putExtra(TransactionActivity.TRANSACTION_ID, hash.toString());

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    String title = getString(R.string.notif_cash_in_title, coin.toFriendlyString());
    final NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
    notification.setSmallIcon(R.mipmap.ic_notification);
    notification.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    notification.setColor(getResources().getColor(R.color.colorPrimary));
    notification.setContentText(msg);
    notification.setContentTitle(title);
    notification.setWhen(System.currentTimeMillis());
    notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notification.setContentIntent(pendingIntent);
    Notification notif = notification.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notif);
}

From source file:io.coldstart.android.GCMIntentService.java

private void sendRateLimitNotification(String rateLimitCount) {
    if (null == rateLimitCount)
        rateLimitCount = "0";

    Intent intent = new Intent(this, TrapListActivity.class);
    intent.putExtra("forceDownload", true);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

    Intent broadcastDownload = new Intent();
    broadcastDownload.setAction(BatchDownloadReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastDownload = PendingIntent.getBroadcast(this, 0, broadcastDownload, 0);

    Intent broadcastIgnore = new Intent();
    broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION);
    PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this, 0, broadcastIgnore, 0);

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

    Notification notification = null;

    if (Build.VERSION.SDK_INT >= 16) {
        notification = new Notification.InboxStyle(new Notification.Builder(this)
                .setContentTitle("Inbound Traps have been rate limited")
                .setContentText(/*from  w w w.  j  av a 2  s.co m*/
                        "\"The number of traps being relayed to your phone has breeched the rate limit.")
                .setSmallIcon(R.drawable.ic_stat_ratelimit).setVibrate(new long[] { 0, 100, 200, 300 })
                .setAutoCancel(true).setSound(uri).setPriority(Notification.PRIORITY_HIGH)
                .setTicker("Inbound Traps have been rate limited")
                .addAction(R.drawable.ic_download_batch, "Get Batched Traps", pBroadcastDownload)
                .addAction(R.drawable.ic_ignore, "Ignore Batch", pBroadcastIgnore))
                        .setBigContentTitle("Inbound Traps have been rate limited")
                        .setSummaryText("Launch ColdStart.io to Manage These Events")
                        .addLine("The number of traps relayed to you has breeched the rate limit.")
                        .addLine("The current number of items queued is " + rateLimitCount).addLine(" ")
                        .addLine("Tap \"Get Batched Traps\" to download the cached traps")
                        .addLine("Tap \"Ignore Batch\" to delete them from the server.")

                        .build();
    } else {
        notification = new Notification.Builder(this).setContentTitle("Inbound Traps have been rate limited")
                .setContentText(
                        "The number of traps being relayed to your phone has breeched the rate limit. The current number of items queued is "
                                + rateLimitCount
                                + "\nTap \"Get Alerts\" to batch download the outstanding traps or tap \"Ignore\" to delete them from the server.")
                .setSmallIcon(R.drawable.ic_stat_ratelimit).setContentIntent(pIntent)
                .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri).build();
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.notify(43524, notification);
}

From source file:com.weddingsingers.wsapp.fcm.MyFirebaseMessagingService.java

private void sendNotification(Alarm alarm, String action) {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(SplashActivity.EXTRA_FRAGNAME, ChattingActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512).setContentTitle("FCM Message")
            .setContentText(alarm.getMessage()).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.windroilla.invoker.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from ww  w. j  a v  a2  s .co m*/
 */
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("New Block Time")
            .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:copytestapp.copytestapp.GCMIntentService.java

void notificationWithBigPicture(Context context, String title, String message, int icon, Bitmap banner,
            Class<?> activityClass, String eventPage, String ad_code, String ad_num) {
        Intent intent = new Intent(context, activityClass);
        intent.putExtra("adUrl", eventPage);
        intent.putExtra("adcodeNum", ad_code);
        intent.putExtra("ad_num", ad_num);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setSmallIcon(icon)
                .setTicker(title).setContentTitle(title).setContentText("??? !")
                .setAutoCancel(true);/*w  ww.  j  a v  a 2 s  .  c  om*/

        NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle();
        style.setBigContentTitle(title);
        style.setSummaryText(message);
        style.bigPicture(banner);

        builder.setStyle(style);
        builder.setContentIntent(pendingIntent);

        builder.setDefaults(Notification.DEFAULT_VIBRATE);
        builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    }

From source file:com.brq.wallet.lt.notification.GcmIntentService.java

private void showAdNotification(String type) {
    Intent intent;//from  ww  w  . j a  v a2  s .c o m
    if (LtApi.AD_TIME_OUT_NOTIFICATION_TYPE.equals(type)) {
        intent = PinProtectedActivity.createIntent(this,
                LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.MY_ADS));
    } else {
        // We don't know this type, so we ignore it
        return;
    }
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    String title = getResources().getString(R.string.lt_mycelium_local_trader_title);
    String message = getResources().getString(R.string.lt_ad_deactivating_message);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setContentText(message).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent)
            .setAutoCancel(true);

    // Add ticker
    builder.setTicker(message);

    LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager();

    // Vibrate
    long[] pattern = { 500, 500 };
    builder.setVibrate(pattern);

    // Make a sound
    if (ltManager.getPlaySoundOnTradeNotification()) {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alarmSound != null) {
            builder.setSound(alarmSound);
        }
    }

    // Notify
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}

From source file:com.mycelium.wallet.lt.notification.GcmIntentService.java

private void showAdNotification(String type) {
    Intent intent;/*from  w  ww  .j  a  va2s . c om*/
    if (LtApi.AD_TIME_OUT_NOTIFICATION_TYPE.equals(type)) {
        intent = PinProtectedActivity.createIntent(this,
                LtMainActivity.createIntent(this, LtMainActivity.TAB_TYPE.MY_ADS));
    } else {
        // We don't know this type, so we ignore it
        return;
    }
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    String title = getResources().getString(R.string.lt_mycelium_local_trader_title);
    String message = getResources().getString(R.string.lt_ad_deactivating_message);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setContentText(message).setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent)
            .setAutoCancel(true);

    // Add ticker
    builder.setTicker(message);

    LocalTraderManager ltManager = MbwManager.getInstance(this).getLocalTraderManager();

    // Vibrate
    long[] pattern = { 500, 500 };
    builder.setVibrate(pattern);

    // Make a sound
    if (ltManager.getPlaySoundOnTradeNotification()) {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alarmSound != null) {
            builder.setSound(alarmSound);
        }
    }

    // Notify
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

protected void initTone() {
    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (alert == null) {
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (alert == null) {
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
        }//  w  w  w  .  j av a 2s.  c  o m
    }
    uri = alert;
}

From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyNewsletter(String title) {
    Intent contentIntent = new Intent(this, MainActivity.class);
    contentIntent.putExtra("navigation_page", MainActivity.PAGE_NEWSLETTER);
    contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 2 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, SettingsActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 3 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(title);/*from  www. j  av  a 2  s . c o m*/
    notifStyle.setBigContentTitle(getString(R.string.notif_newsletter_title));

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_newsletter_title)).setContentText(title)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off,
                    getString(R.string.notif_action_options), settingsPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(NOTIFICATION_ID_NEWSLETTER, notificationBuilder.build());
}

From source file:com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService.java

private void generateNotification(Context context, String ticker, String title, String msg, int icon,
        Intent intent, String sound, int notificationId, MFPInternalPushMessage message) {

    int androidSDKVersion = Build.VERSION.SDK_INT;
    long when = System.currentTimeMillis();
    Notification notification = null;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    if (message.getGcmStyle() != null && androidSDKVersion > 21) {
        NotificationCompat.Builder mBuilder = null;
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        try {//w  ww  .  j  a  va2 s  .c  o  m
            JSONObject gcmStyleObject = new JSONObject(message.getGcmStyle());
            String type = gcmStyleObject.getString(TYPE);

            if (type != null && type.equalsIgnoreCase(PICTURE_NOTIFICATION)) {
                Bitmap remote_picture = null;
                NotificationCompat.BigPictureStyle notificationStyle = new NotificationCompat.BigPictureStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));

                try {
                    remote_picture = new getBitMapBigPictureNotification()
                            .execute(gcmStyleObject.getString(URL)).get();
                } catch (Exception e) {
                    logger.error(
                            "MFPPushIntentService:generateNotification() - Error while fetching image file.");
                }
                if (remote_picture != null) {
                    notificationStyle.bigPicture(remote_picture);
                }

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setLargeIcon(remote_picture).setAutoCancel(true)
                        .setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();

            } else if (type != null && type.equalsIgnoreCase(BIGTEXT_NOTIFICATION)) {
                NotificationCompat.BigTextStyle notificationStyle = new NotificationCompat.BigTextStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));
                notificationStyle.bigText(gcmStyleObject.getString(TEXT));

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();
            } else if (type != null && type.equalsIgnoreCase(INBOX_NOTIFICATION)) {
                NotificationCompat.InboxStyle notificationStyle = new NotificationCompat.InboxStyle();
                notificationStyle.setBigContentTitle(ticker);
                notificationStyle.setSummaryText(gcmStyleObject.getString(TITLE));

                String lines = gcmStyleObject.getString(LINES).replaceAll("\\[", "").replaceAll("\\]", "");
                String[] lineArray = lines.split(",");

                for (String line : lineArray) {
                    notificationStyle.addLine(line);
                }

                mBuilder = new NotificationCompat.Builder(context);
                notification = mBuilder.setSmallIcon(icon).setAutoCancel(true).setContentTitle(title)
                        .setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                                PendingIntent.FLAG_UPDATE_CURRENT))
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(msg).setStyle(notificationStyle).build();
            }

            notification.flags = Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(notificationId, notification);
        } catch (JSONException e) {
            logger.error("MFPPushIntentService:generateNotification() - Error while parsing JSON.");
        }

    } else {
        if (androidSDKVersion > 10) {
            builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker).setWhen(when)
                    .setAutoCancel(true).setContentTitle(title).setContentText(msg)
                    .setSound(getNotificationSoundUri(context, sound));

            if (androidSDKVersion > 15) {
                int priority = getPriorityOfMessage(message);
                builder.setPriority(priority);
                notification = builder.build();
            }

            if (androidSDKVersion > 19) {
                //As new material theme is very light, the icon is not shown clearly
                //hence setting the background of icon to black
                builder.setColor(Color.BLACK);
                Boolean isBridgeSet = message.getBridge();
                if (!isBridgeSet) {
                    // show notification only on current device.
                    builder.setLocalOnly(true);
                }

                notification = builder.build();
                int receivedVisibility = 1;
                String visibility = message.getVisibility();
                if (visibility != null && visibility.equalsIgnoreCase(MFPPushConstants.VISIBILITY_PRIVATE)) {
                    receivedVisibility = 0;
                }
                if (receivedVisibility == Notification.VISIBILITY_PRIVATE && message.getRedact() != null) {
                    builder.setContentIntent(PendingIntent.getActivity(context, notificationId, intent,
                            PendingIntent.FLAG_UPDATE_CURRENT)).setSmallIcon(icon).setTicker(ticker)
                            .setWhen(when).setAutoCancel(true).setContentTitle(title)
                            .setContentText(message.getRedact())
                            .setSound(getNotificationSoundUri(context, sound));

                    notification.publicVersion = builder.build();
                }
            }

            if (androidSDKVersion > 21) {
                String setPriority = message.getPriority();
                if (setPriority != null && setPriority.equalsIgnoreCase(MFPPushConstants.PRIORITY_MAX)) {
                    //heads-up notification
                    builder.setContentText(msg).setFullScreenIntent(PendingIntent.getActivity(context,
                            notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT), true);
                    notification = builder.build();
                }
            }

        } else {
            notification = builder
                    .setContentIntent(
                            PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT))
                    .setSmallIcon(icon).setTicker(ticker).setWhen(when).setAutoCancel(true)
                    .setContentTitle(title).setContentText(msg)
                    .setSound(getNotificationSoundUri(context, sound)).build();
        }

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

        notificationManager.notify(notificationId, notification);
    }
}