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.nbplus.vbroadlistener.gcm.MyGcmListenerService.java

private void showNotification(Context context, int notificationId, int smallIconId, String title,
        String contentText, String bigTitle, String bigContentText, String summaryText, String ticker,
        Intent intent) {// w  ww .  j av a  2  s . c om
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);

    if (smallIconId == 0) {
        builder.setSmallIcon(R.mipmap.ic_launcher);
    } else {
        builder.setSmallIcon(smallIconId);
    }
    builder.setWhen(System.currentTimeMillis());
    //builder.setNumber(10);

    if (!StringUtils.isEmptyString(ticker)) {
        builder.setTicker(ticker);
    }

    if (StringUtils.isEmptyString(title)) {
        builder.setContentTitle(PackageUtils.getApplicationName(context));
    } else {
        builder.setContentTitle(title);
    }
    builder.setContentText(contentText);
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    // big title and text
    if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) {
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        if (!StringUtils.isEmptyString(summaryText)) {
            style.setSummaryText(summaryText);
        }
        style.setBigContentTitle(bigTitle);
        style.bigText(bigContentText);

        builder.setStyle(style);
    }

    if (intent != null) {
        intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
    }

    notificationManager.notify(notificationId, builder.build());
}

From source file:com.brq.wallet.activity.receive.ReceiveCoinsActivity.java

@Subscribe
public void syncStopped(SyncStopped event) {
    TextView tvRecv = (TextView) findViewById(R.id.tvReceived);
    TextView tvRecvWarning = (TextView) findViewById(R.id.tvReceivedWarningAmount);
    final WalletAccount selectedAccount = _mbwManager.getSelectedAccount();
    final List<TransactionSummary> transactionsSince = selectedAccount.getTransactionsSince(_receivingSince);
    final ArrayList<TransactionSummary> interesting = new ArrayList<TransactionSummary>();
    CurrencyValue sum = ExactBitcoinValue.ZERO;
    for (TransactionSummary item : transactionsSince) {
        if (item.toAddresses.contains(_address)) {
            interesting.add(item);/*from   w  w w.  jav a2 s.  c  om*/
            sum = item.value;
        }
    }

    if (interesting.size() > 0) {
        tvRecv.setText(getString(R.string.incoming_payment)
                + Utils.getFormattedValueWithUnit(sum, _mbwManager.getBitcoinDenomination()));
        // if the user specified an amount, also check it if it matches up...
        if (!CurrencyValue.isNullOrZero(_amount)) {
            tvRecvWarning.setVisibility(sum.equals(_amount) ? View.GONE : View.VISIBLE);
        } else {
            tvRecvWarning.setVisibility(View.GONE);
        }
        tvRecv.setVisibility(View.VISIBLE);
        if (!sum.equals(_lastAddressBalance)) {
            NotificationManager notificationManager = (NotificationManager) this
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setSound(soundUri, AudioManager.STREAM_NOTIFICATION); //This sets the sound to play
            notificationManager.notify(0, mBuilder.build());

            _lastAddressBalance = sum;
        }
    } else {
        tvRecv.setVisibility(View.GONE);
    }
}

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

public void notifyUndefined(String title, String text, String URL) {
    Uri webpage = Uri.parse(URL);
    Intent contentIntent = new Intent(Intent.ACTION_VIEW, webpage);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

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

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

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(text);/*  ww  w. j  av a  2  s  . c  om*/
    notifStyle.setBigContentTitle(title);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi).setContentTitle(title).setContentText(text)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle);

    // 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_UNDEFINED, notificationBuilder.build());
}

From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java

private void playNotificationAlarm(Context context, int textResId) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);/*from  ww w.  ja  va 2s . com*/
    notificationManager.notify(Constants.PUSH_NOTIFICATION_ALARM_ID, builder.build());

    Toast.makeText(context, textResId, Toast.LENGTH_SHORT).show();
}

From source file:com.nbplus.vbroadlauncher.BroadcastPushReceiver.java

private void showNotification(Context context, int notificationId, String title, String contentText,
        String bigTitle, String bigContentText, String summaryText, String ticker, Intent intent) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSound(soundUri);//  ww w  .  ja  va  2  s .c om

    builder.setSmallIcon(R.drawable.ic_notification_noti);
    builder.setWhen(System.currentTimeMillis());
    //builder.setNumber(10);

    if (!StringUtils.isEmptyString(ticker)) {
        builder.setTicker(ticker);
    }

    if (StringUtils.isEmptyString(title)) {
        builder.setContentTitle(PackageUtils.getApplicationName(context));
    } else {
        builder.setContentTitle(title);
    }
    builder.setContentText(contentText);
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    builder.setAutoCancel(true);

    // big title and text
    if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) {
        NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder);
        if (!StringUtils.isEmptyString(summaryText)) {
            style.setSummaryText(summaryText);
        }
        style.setBigContentTitle(bigTitle);
        style.bigText(bigContentText);

        builder.setStyle(style);
    }

    if (intent != null) {
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
    }

    notificationManager.notify(notificationId, builder.build());
}

From source file:com.visva.voicerecorder.utils.Utils.java

public static void showNotificationAfterCalling(Context context, String phoneName, String phoneNo,
        String createdDate) {//from  w ww . j av  a  2s  .co  m
    Resources res = context.getResources();
    String newRecord = res.getString(R.string.you_have_new_record);
    String favorite = res.getString(R.string.favourite);
    String addNote = res.getString(R.string.add_note);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle(phoneName)
            .setContentText(newRecord);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSound(alarmSound);

    int isFavourite = Utils.isCheckFavouriteContactByPhoneNo(context, phoneNo);
    Bundle bundle = new Bundle();
    bundle.putString(MyCallRecorderConstant.EXTRA_PHONE_NAME, phoneName);
    bundle.putString(MyCallRecorderConstant.EXTRA_PHONE_NO, phoneNo);
    bundle.putString(MyCallRecorderConstant.EXTRA_CREATED_DATE, createdDate);
    if (isFavourite == 0) {
        //favorite intent
        Intent favoriteIntent = new Intent();
        favoriteIntent.setAction(MyCallRecorderConstant.FAVORITE_INTENT);
        favoriteIntent.putExtras(bundle);
        PendingIntent pendingFavoriteIntent = PendingIntent.getBroadcast(context,
                MyCallRecorderConstant.NOTIFICATION_ID, favoriteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_star_outline_white_36dp, favorite, pendingFavoriteIntent);
    }

    //Make a note intent
    Intent makeNoteIntent = new Intent();
    makeNoteIntent.setAction(MyCallRecorderConstant.MAKE_NOTE_INTENT);
    makeNoteIntent.putExtras(bundle);
    PendingIntent pendingMakeNoteIntent = PendingIntent.getBroadcast(context,
            MyCallRecorderConstant.NOTIFICATION_ID, makeNoteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.addAction(R.drawable.ic_customer_create, addNote, pendingMakeNoteIntent);

    Intent resultIntent = new Intent(context, ActivityHome.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(ActivityHome.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    builder.setPriority(NotificationCompat.PRIORITY_MAX);
    builder.setWhen(0);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(MyCallRecorderConstant.NOTIFICATION_ID, builder.build());
}

From source file:com.mattprecious.prioritysms.activity.ProfileListActivity.java

private void doUpdate(int from, int to) {
    switch (from) {
    case 1:/*from w  w  w  .  j  av  a  2s .c  om*/
    case 2:
        // too old, don't worry
        break;
    case 3:
        // move 'contact' preference to 'sms_contact'
        preferences.edit().putString("sms_contact", preferences.getString("contact", null)).remove("contact")
                .commit();

    case 4:
        // enabled defaulted to false previously
        preferences.edit()
                .putBoolean(getString(R.string.pref_key_enabled), preferences.getBoolean("enabled", false))
                .commit();

        SmsProfile smsProfile = new SmsProfile();
        smsProfile.setName("SMS Profile");

        PhoneProfile phoneProfile = new PhoneProfile();
        phoneProfile.setName("Phone Profile");

        String ringtone = preferences.getString("alarm", null);
        Uri ringtoneUri = ringtone == null ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)
                : Uri.parse(ringtone);
        smsProfile.setRingtone(ringtoneUri);
        phoneProfile.setRingtone(ringtoneUri);

        boolean vibrate = preferences.getBoolean("vibrate", false);
        smsProfile.setVibrate(vibrate);
        phoneProfile.setVibrate(vibrate);

        // import the SMS settings
        boolean smsWorthSaving = false;

        String smsLookup = preferences.getString("sms_contact", null);
        if (preferences.getBoolean("filter_contact", false) && !Strings.isBlank(smsLookup)) {
            smsProfile.addContact(smsLookup);
            smsWorthSaving = true;
        }

        String keywords = preferences.getString("keyword", null);
        if (preferences.getBoolean("filter_keyword", false) && !Strings.isBlank(keywords)) {
            String[] keywordArr = keywords.split(",");
            smsProfile.setKeywords(new LinkedHashSet<String>(Arrays.asList(keywordArr)));
            smsWorthSaving = true;
        }

        if (smsWorthSaving) {
            smsProfile.save(this);
        }

        // import the missed call settings
        phoneProfile.setEnabled(preferences.getBoolean("on_call", false));

        boolean phoneWorthSaving = false;

        String phoneLookup = preferences.getString("call_contact", null);
        if (!Strings.isBlank(phoneLookup)) {
            phoneProfile.addContact(phoneLookup);
            phoneWorthSaving = true;
        }

        if (phoneWorthSaving) {
            phoneProfile.save(this);
        }

        // delete all those old preferences
        preferences.edit().remove("filter_keyword").remove("keyword").remove("filter_contact")
                .remove("sms_contact").remove("on_call").remove("call_contact").remove("alarm")
                .remove("override").remove("vibrate").commit();
    }
}

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

private Uri getNotificationSoundUri(Context context, String sound) {
    Uri uri = null;//from   www.j  a v a  2  s  . c o m

    if (sound == null) {
        uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    } else if (!(sound.trim().isEmpty())) {
        String soundResourceString = sound;
        try {
            if (soundResourceString.contains(".")) {
                soundResourceString = soundResourceString.substring(0, soundResourceString.indexOf("."));
            }
            int resourceId = getResourceId(context, RAW, soundResourceString);
            if (resourceId == -1) {
                logger.error(
                        "MFPPushIntentService:getNotificationSoundUri() - Specified sound file is not found in res/raw");
            }
            uri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId);
        } catch (Exception e) {
            logger.error("MFPPushIntentService:getNotificationSoundUri() - Exception while parsing sound file");
        }
    }

    return uri;
}

From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java

private Notification createNotification(final int iconResId, final String title, final String contentText,
        final String imageUrl, final String imageIconUrl, final String imageSmallIconUrl,
        final PendingIntent contentIntent) {
    log.info("Create Notification:" + title + ", Content:" + contentText);
    if (android.os.Build.VERSION.SDK_INT < ANDROID_JELLYBEAN) {
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    }//from   www  .ja va 2  s .  c om

    if (!initClassesAndMethodsByReflection()) {
        // fall back to creating the legacy notification.
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    }

    final Object notificationBuilder;
    final Object bigTextStyle;
    final Object bigPictureStyle;

    try {
        notificationBuilder = notificationBuilderConstructor
                .newInstance(pinpointContext.getApplicationContext());
        bigTextStyle = notificationBigTextStyleClass.newInstance();
        bigPictureStyle = notificationBigPictureStyleClass.newInstance();
    } catch (final InvocationTargetException ex) {
        log.debug("Can't invoke notification builder constructor. : " + ex.getMessage(), ex);
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    } catch (final IllegalAccessException ex) {
        log.debug("Can't access notification builder or bigTextStyle or bigPictureStyle classes. : "
                + ex.getMessage(), ex);
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    } catch (final InstantiationException ex) {
        log.debug(
                "Exception while instantiating notification builder or bigTextStyle or bigPictureStyle classes. : "
                        + ex.getMessage(),
                ex);
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    }

    try {
        setContentTitleMethod.invoke(notificationBuilder, title);
        setContentTextMethod.invoke(notificationBuilder, contentText);
        setContentIntent.invoke(notificationBuilder, contentIntent);
        setPriorityMethod.invoke(notificationBuilder, 1);
        final Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        setSoundMethod.invoke(notificationBuilder, defaultSoundUri);

        if (!buildNotificationIcons(iconResId, imageIconUrl, imageSmallIconUrl, notificationBuilder)) {
            return createLegacyNotification(iconResId, title, contentText, contentIntent);
        }

        if (imageUrl != null) {
            try {
                notificationImage = new DownloadImageTask().execute(imageUrl).get();
                if (notificationImage != null) {
                    bigPictureMethod.invoke(bigPictureStyle, notificationImage);
                    setSummaryMethod.invoke(bigPictureStyle, contentText);
                    setStyleMethod.invoke(notificationBuilder, bigPictureStyle);
                } else {
                    bigTextMethod.invoke(bigTextStyle, contentText);
                    setStyleMethod.invoke(notificationBuilder, bigTextStyle);
                }
            } catch (final InterruptedException e) {
                log.error("Interrupted when downloading image : " + e.getMessage(), e);
            } catch (final ExecutionException e) {
                log.error("Failed execute download image thread : " + e.getMessage(), e);
            }
        }

        return (Notification) buildMethod.invoke(notificationBuilder);
    } catch (final InvocationTargetException ex) {
        log.debug("Can't invoke notification builder methods. : " + ex.getMessage(), ex);
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    } catch (final IllegalAccessException ex) {
        log.debug("Can't access notification builder methods. : " + ex.getMessage(), ex);
        return createLegacyNotification(iconResId, title, contentText, contentIntent);
    }
}

From source file:com.visva.voicerecorder.utils.Utils.java

public static void showNotificationAtReminderTime(Context context, String title, String note) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle(title)
            .setContentText(note);//from   www  . java 2s  . c  o m
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSound(alarmSound);

    Intent resultIntent = new Intent(context, ActivityHome.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(ActivityHome.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, builder.build());
}