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.hugosama.samalinne.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from   w  ww.j av  a 2s  .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);

    Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Samalinne").setContentText(messageBody)
            .setAutoCancel(true).setLargeIcon(image).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.donteatalone.asheeshsharma.capstone_porject2.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//* w  w  w. j a  v  a2  s.co m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, LoginChatActivity.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.sample_img2).setContentTitle("SendBird").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:asia.covisoft.goom.gcm.GoOmUserGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w  w  w . ja va  2 s.c  o  m*/
 */
private void sendNotification(String message, Driverconfirm response) {

    Intent intent = new Intent(this, HistoryDetailsActivity.class);
    trandingId = response.getTradingid();
    intent.putExtra(Extras.TRADING_ID, trandingId);
    intent.putExtra(Extras.HISTORY_STATE, false);
    if (response.getValue().equals("tip")) {
        intent.putExtra(Extras.REQUEST_TIP, true);
        intent.putExtra(Extras.MAX_TIP, response.getMaxsuggest());
        intent.putExtra(Extras.MIN_TIP, response.getMinsuggest());
        cancelTip();
    }

    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(getString(R.string.app_name_full))
            .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.androdevlinux.percy.bitfly.Core.Services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from  ww  w  .ja  va 2 s  .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.drawable.ic_menu_camera).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:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//from  ww  w .  ja  va 2 s . com
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {

    String message = data.getString("message");

    if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) {
        Log.d(TAG, "Message: " + message);

        try {

            JSONObject object = new JSONObject(message);

            ArrayList<String> eventItem = new ArrayList<>();
            eventItem.add(object.toString());

            broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem);

            if (!GameSingleton.activityForeground) {

                if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {

                    GameMessageTopic topic = GameMessageTopic
                            .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC));

                    ChallengeMessage challengeMessage = new ChallengeMessage(topic,
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));

                    Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : "
                            + challengeMessage.getChallengerId());

                    Intent intent2 = new Intent(this, DeviceListActivity.class);
                    intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2,
                            PendingIntent.FLAG_ONE_SHOT);
                    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!")
                            .setContentText("challenged by " + challengeMessage.getChallengerName())
                            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
                    NotificationManager notificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build());

                    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                    boolean isScreenOn = pm.isScreenOn();
                    if (isScreenOn == false) {
                        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                                | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock");
                        wl.acquire(10000);
                        PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                                "MyCpuLock");
                        wl_cpu.acquire(10000);
                    }

                    GameSingleton.pendingChallengeMessage = challengeMessage;
                    GameSingleton.pendingChallenge = true;
                }
            }

        } catch (JSONException e) {
            e.printStackTrace();

        }
    }
}

From source file:com.dotcom.jamaat.fcm.GCMListenerService.java

/**
 * Create and show a simple notification containing the received GCM
 * message./*from   ww  w  .j  ava  2 s  . c o  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:com.bosco.noticeboard.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param note Notice received from server.
 *///from w w  w . j av  a  2 s .c  om
private void sendNotification(Notice note) {
    Intent intent = new Intent(this, NoticeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("Notice", note);
    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)
            .setContentTitle(note.subject).setSmallIcon(R.drawable.normal_bell).setContentText(note.content)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    if (note.priority == 1) {
        notificationBuilder.setColor(getResources().getColor(R.color.icon_normal));
    } else if (note.priority == 2) {
        notificationBuilder.setColor(getResources().getColor(R.color.icon_important));
    }

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

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

From source file:com.korchid.msg.firebase.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*w  w  w .j a va  2s  . com*/
private void sendNotification(String messageBody) {
    Log.d(TAG, "sendNotification");
    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_logo).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.sumang.chatdemo.MyFirebaseMessagingService.java

/**
 * Handle time allotted to BroadcastReceivers.
 *///www.j  av a 2  s  . c  o m
private void handleNow(String title, String messageBody) {
    Log.d(TAG, "Short lived task is done.");
    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).setGroup("ABC")
            .setGroupSummary(true).setSmallIcon(R.drawable.messenger_bubble_small_white)
            .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext());

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

From source file:com.ct.fitorto.gcm.GcmService.java

private void sendNotification(String msg, String title) {

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

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_fitorto)
            .setLargeIcon((BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)))
            .setContentTitle(title).setContentText(msg).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
    //manager.putPreferenceIntValues(ApplicationData.NOTIFICATION_ID, (notificationId + 1));
}