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.dotcom.jamaatAdmin.fcm.GCMListenerService.java

/**
 * Create and show a simple notification containing the received GCM
 * message./*  w  w w. ja v  a2s  . co  m*/
 * <p/>
 * <p/>
 * GCM message received.
 */
public void displayNotificationInNotificationBar(Map data) {
    try {
        String messageData = data.get("message").toString();
        int notifyID = Constants.NOTIFICATION_ID;
        //String eData = data.getString("extra_data");
        String message = "";
        if (!TextUtils.isEmpty(messageData)) {
            JSONObject extra_data = new JSONObject(messageData);
            message = extra_data.optString("message");
        }

        // This intent is fired when notification is clicked

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

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Intent intent;
        String messages = SharedPreferencesManager.getStringPreference("notificationMessage", null);
        if (messages != null && !messages.isEmpty()) {
            messages = message + "," + messages;
            SharedPreferencesManager.setPreference("notificationMessage", messages);

            intent = new Intent(this, NotificationActivity.class);
        } else {
            SharedPreferencesManager.setPreference("notificationMessage", message);

            intent = new Intent(this, NotificationActivity.class);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        String currentMessages = SharedPreferencesManager.getStringPreference("notificationMessage", null);
        String[] messagesArray = currentMessages.split(",");

        int count = messagesArray.length;
        if (messagesArray.length == 0) {

            notificationManager.cancel(notifyID);
            return;
        }

        final String GROUP_KEY_MESSAGES = "group_key_messages";

        // Group notification that will be visible on the phone
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setTicker(getString(R.string.app_name)).setDefaults(Notification.DEFAULT_ALL)
                .setContentTitle(getString(R.string.app_name)).setSound(defaultSoundUri).setAutoCancel(true)
                .setOnlyAlertOnce(false)
                //               .setPriority(Notification.PRIORITY_MAX)
                //               .setOngoing(true)
                //               .setWhen( System.currentTimeMillis() )
                .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES)
                .setGroupSummary(true).build();

        NotificationCompat.Style style;
        if (count > 1) {
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            style = inboxStyle;

            mBuilder.setContentTitle(getString(R.string.app_name));

            for (String r : messagesArray) {
                inboxStyle.addLine(r);
            }
            mBuilder.setContentText(count + " new messages");
            inboxStyle.setBigContentTitle(getString(R.string.app_name));
            inboxStyle.setSummaryText(count + " new messages");
        } else {
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            style = bigTextStyle;

            //            bigTextStyle.setBigContentTitle(messagesArray[0].substring(0, 10).concat(" ..."));
            bigTextStyle.setBigContentTitle(getString(R.string.app_name));
            mBuilder.setContentText(message);
            bigTextStyle.bigText(message);
            //            bigTextStyle.setSummaryText(count + " new event");
        }
        mBuilder.setStyle(style);

        NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this);
        notificationManager1.notify(notifyID, mBuilder.build());

    } catch (Exception ex) {

    }
}

From source file:kaist.cs492c_2015.washerbrowser.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  w ww.  ja v a  2 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("Find available washer")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }).setSmallIcon(R.drawable.washer_green)
            .setContentIntent(pendingIntent);

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

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

    launchPopupActivity(this, message);
}

From source file:com.prova.provafirebase.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*w w  w .ja  v a 2  s  . 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.free).setContentTitle("TINGNPADELLA").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.example.user.rideshareapp1.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 a  2  s.com*/
 */
private void sendNotification(String message) {

    String[] parts = message.split("`");

    Intent intent = new Intent(this, approve_ride.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_logo_web).setContentTitle(parts[0])
            .setContentText(parts[1] + ":" + parts[2]).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.multimediainformatika.bukabengkel.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*  ww  w .ja v  a2s  .c  om*/
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("Know Plus").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.devnoobs.bmr.Powiadomienia.java

@Override
public void onReceive(Context c, Intent i) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c).setSmallIcon(R.drawable.ic_note)
            .setContentTitle("Powiadomienie ").setContentText("Testowe powiadomienie o danej godzinie");
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    mBuilder.setSound(alarmSound);/*from  ww w. java 2 s .  co  m*/
    NotificationManager powiadomienie = (NotificationManager) c.getSystemService(c.NOTIFICATION_SERVICE);
    powiadomienie.notify(1, mBuilder.build());

}

From source file:com.inverita.nazarko.deeplink.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 *
 */// w ww . ja  v a  2 s . c  o  m
private void sendNotification(Map<String, String> map) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("link", map.get("link"));
    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.firebase_lockup_400).setContentTitle("FCM Message").setContentText("test")
            .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.pr.carjoin.chat.MyFirebaseMessagingService.java

private void showNotification(Map<String, String> payLoad, String messageBody) {
    String operationCode = payLoad.get(Util.OPERATION_CODE);
    Intent intent = new Intent(this, YourTripsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Util.OPERATION_CODE, payLoad.get(Util.OPERATION_CODE));
    intent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
    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.mipmap.ic_launcher).setContentTitle("CarJoin").setAutoCancel(true)
            .setContentText(messageBody).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    switch (operationCode) {
    case "5000":
        Intent acceptedIntent = new Intent(this, NotificationReceiver.class);
        Intent declinedIntent = new Intent(this, NotificationReceiver.class);
        acceptedIntent.setAction(Constants.ACCEPTED);
        acceptedIntent.putExtra("actionCode", "5000");
        acceptedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        acceptedIntent.putExtra("valueToUpdate", Constants.ACCEPTED);

        PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(this, 0, acceptedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        declinedIntent.setAction(Constants.REJECTED);
        declinedIntent.putExtra("actionCode", "5000");
        declinedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        declinedIntent.putExtra("valueToUpdate", Constants.REJECTED);

        PendingIntent declinePendingIntent = PendingIntent.getBroadcast(this, 0, declinedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notificationBuilder.addAction(R.drawable.decline, "Decline", declinePendingIntent);
        notificationBuilder.addAction(R.drawable.accept, "Accept", acceptPendingIntent);
        notificationManager.notify(5000, notificationBuilder.build());
        break;/*from   w  w w . j a  v  a  2  s .  c  o  m*/
    }

}

From source file:com.example.llh_pc.it_support.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
        /*from ww w . j ava  2s .c  o m*/
 */
private void sendNotification(String message, String avatar, String name) {
    Intent intent = new Intent(this, frmTabHost.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.its_logo_72x72px).setContentTitle("IT Support").setContentText(name)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(++Flags.number_notification /* ID of notification */,
            notificationBuilder.build());
}

From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java

private void sendNotification(String messageTitle, String messageBody) {
    Intent intent = MainActivity.makeIntent(this);
    intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(messageTitle);
    bigTextStyle.bigText(messageBody);/* w  w w .j  av  a 2  s  . c  om*/

    Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

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

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle)
            .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true)
            .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200)
            .setPriority(Notification.PRIORITY_MAX);

    //for vibration
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);

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

    long time = new Date().getTime();
    String tmpStr = String.valueOf(time);
    String last4Str = tmpStr.substring(tmpStr.length() - 5);
    int notificationId = Integer.valueOf(last4Str);

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