Example usage for android.media RingtoneManager TYPE_NOTIFICATION

List of usage examples for android.media RingtoneManager TYPE_NOTIFICATION

Introduction

In this page you can find the example usage for android.media RingtoneManager TYPE_NOTIFICATION.

Prototype

int TYPE_NOTIFICATION

To view the source code for android.media RingtoneManager TYPE_NOTIFICATION.

Click Source Link

Document

Type that refers to sounds that are used for notifications.

Usage

From source file:com.itime.team.itime.services.ITimeGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM message received./*w  ww.  j av a  2 s . co m*/
 */
private void sendNotification(Bundle data) {
    ParcelableMessage message = new ParcelableMessage(data);
    if (message.messageType == null) {
        return;
    }

    Intent intent = new Intent(this, CheckLoginActivity.class);
    // Set ACTION_MAIN and CATEGORY_LAUNCHER is the key!
    // Even though CheckLoginActivity is finish and no longer exist, the app will return to the
    // foreground and CheckLoginActivity would not be created again. Demonstrated in the logcat
    // where on CheckLoginActivity onCreate, onResume.
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    // Do add this flags otherwise it will clear all the activity in the stack
    //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);
    String messageTitle = data.getString("alert", "ITime Message");
    String messageBody = data.getString("message_body", "ITime Message");
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notifications_active_black).setContentTitle(messageTitle)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification notificationType1() {
    Bitmap smallIconBitmap = getMeBitmap(smallIcon);
    if (smallIconBitmap == null)
        return null;
    Bitmap largeImageBitmap = getMeBitmap(largeIcon);
    if (largeImageBitmap == null)
        return null;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setTicker(title).setSubText(subtitle).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(smallIconBitmap).setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(largeImageBitmap))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    builder.setContentIntent(pendingIntent);
    return builder.build();

}

From source file:au.com.websitemasters.schools.lcps.push.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w  w  w .  j a  va  2 s  .  c o m
 */

public void sendNotification(String message, Class clas) {

    //load not readed. +1. save em.
    int notReaded = ((SchoolsApplication) getApplicationContext()).loadBadgesCount();
    notReaded++;
    ((SchoolsApplication) getApplicationContext()).saveBadgesCount(notReaded);

    //show it on badge.
    ShortcutBadger.applyCount(getApplicationContext(), notReaded);

    Intent intent = new Intent(this, clas);
    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.logo_gray).setContentTitle("Leschenault Catholic Primary School")
            .setContentText(message).setAutoCancel(true).setNumber(notReaded).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    //push realtime refresh of lists (ANN)
    Intent intentBroadcast = new Intent(BROADCAST_ACTION);
    sendBroadcast(intentBroadcast);
}

From source file:com.example.android.pantry.scanner.BarcodeScannerActivity.java

@Override
public void handleResult(Result rawResult) {
    try {//from  www.  ja v a  2  s.  c  o  m
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }

    mLastBarcodeValue = rawResult.getText();
    mLastBarcodeType = rawResult.getBarcodeFormat().toString();
    PantryDbHelper dbHelper = new PantryDbHelper(this);
    mDb = dbHelper.getWritableDatabase();

    String productInfo = "";
    String quantityString = "";
    mLastInventoryItem = null;

    Barcode barcode = BarcodesTable.getBarcodeByValue(mDb, mLastBarcodeValue);
    if (barcode == null) {
        String message = "Product not found.\nSearch the big product database?";

        showSearchDialog(message);

    } else {
        productInfo = barcode.getProduct().getBrand() + " " + barcode.getProduct().getName();
        long productId = barcode.getProduct().getProductId();

        buildInventoryItemAndShowMessageDialog(productInfo, barcode.getProduct(), productId);
    }

}

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

private void sendBatchNotification(String batchCount) {
    if (null == batchCount)
        batchCount = "1+";

    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("A batch of Traps has been sent")
                        .setContentText("\"Batched traps are waiting to be downloaded")
                        .setSmallIcon(R.drawable.ic_stat_ratelimit).setVibrate(new long[] { 0, 100, 200, 300 })
                        .setAutoCancel(true).setSound(uri).setPriority(Notification.PRIORITY_HIGH)
                        .setTicker("A batch of Traps has been sent")
                        .addAction(R.drawable.ic_download_batch, "Get Batched Traps", pBroadcastDownload)
                        .addAction(R.drawable.ic_ignore, "Ignore Batch", pBroadcastIgnore))
                                .setBigContentTitle("A batch of Traps has been sent")
                                .setSummaryText("Launch ColdStart.io to Manage These Events")
                                .addLine("A number of traps have been sent and batched for delivery")
                                .addLine("The current number of items queued is " + batchCount).addLine(" ")
                                .addLine("Tap \"Get Batched Traps\" to download the cached traps")
                                .addLine("Tap \"Ignore Batch\" to delete them from the server.")

                                .build();
    } else {//from   w ww  .ja  v a 2 s  .co  m
        notification = new Notification.Builder(this).setContentTitle("A batch of Traps has been sent")
                .setContentText(
                        "A number of traps have been sent and batched for delivery. The current number of items queued is "
                                + batchCount
                                + "\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.dotcom.jamaat.fcm.GCMListenerService.java

public void setNotificationSound() {
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    mBuilder.setSound(defaultSoundUri);/*  w  ww.  j a v a 2s . co  m*/
    //    mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this);
    notificationManager1.notify(1, mBuilder.build());
}

From source file:au.com.websitemasters.schools.thornlie.push.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  www. j  a  v a 2s .  c  o  m
 */

private void sendNotification(String message, Class clas) {

    //load not readed. +1. save em.
    int notReaded = ((SchoolsApplication) getApplicationContext()).loadBadgesCount();
    notReaded = notReaded + 1;
    ((SchoolsApplication) getApplicationContext()).saveBadgesCount(notReaded);

    //show it on badge.
    ShortcutBadger.applyCount(getApplicationContext(), notReaded);

    Intent intent = new Intent(this, clas);
    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.logopush).setContentTitle("Sacred Heart School Thornlie")
            .setContentText(message).setAutoCancel(true).setNumber(notReaded).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    //push realtime refresh of lists (ANN)
    Intent intentBroadcast = new Intent(BROADCAST_ACTION);
    sendBroadcast(intentBroadcast);
}

From source file:com.raspi.chatapp.util.Notification.java

public void createNotification(String buddyId, String name, String message, String type) {
    SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);

    if (defaultSharedPreferences
            .getBoolean(context.getResources().getString(R.string.pref_key_new_message_notifications), true)) {
        int index = buddyId.indexOf("@");
        if (index != -1)
            buddyId = buddyId.substring(0, index);
        if (name == null)
            name = buddyId;//from www.  j av  a  2s  .co m
        Log.d("DEBUG", "creating notification: " + buddyId + "|" + name + "|" + message);
        Intent resultIntent = new Intent(context, ChatActivity.class);
        resultIntent.setAction(NOTIFICATION_CLICK);
        String oldBuddyId = getOldBuddyId();
        Log.d("DEBUG",
                (oldBuddyId == null) ? ("oldBuddy is null (later " + buddyId) : ("oldBuddy: " + oldBuddyId));
        if (oldBuddyId == null || oldBuddyId.equals("")) {
            oldBuddyId = buddyId;
            setOldBuddyId(buddyId);
        }
        if (oldBuddyId.equals(buddyId)) {
            resultIntent.putExtra(Constants.BUDDY_ID, buddyId);
            resultIntent.putExtra(Constants.CHAT_NAME, name);
        }

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(ChatActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationManager nm = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE));
        NotificationCompat.Style style;

        String[] previousNotifications = readJSONArray(CURRENT_NOTIFICATIONS);
        String title;
        String[] currentNotifications = Arrays.copyOf(previousNotifications, previousNotifications.length + 1);
        currentNotifications[currentNotifications.length - 1] = name + ": " + message;
        if (previousNotifications.length == 0) {
            style = new NotificationCompat.BigTextStyle();
            NotificationCompat.BigTextStyle bigTextStyle = ((NotificationCompat.BigTextStyle) style);
            title = context.getResources().getString(R.string.new_message) + " "
                    + context.getResources().getString(R.string.from) + " " + name;
            bigTextStyle.bigText(currentNotifications[0]);
            bigTextStyle.setBigContentTitle(title);
        } else {
            style = new NotificationCompat.InboxStyle();
            NotificationCompat.InboxStyle inboxStyle = (NotificationCompat.InboxStyle) style;
            title = (previousNotifications.length + 1) + " "
                    + context.getResources().getString(R.string.new_messages);
            for (String s : currentNotifications)
                if (s != null && !"".equals(s))
                    inboxStyle.addLine(s);
            inboxStyle.setSummaryText(
                    (currentNotifications.length > 2) ? ("+" + (currentNotifications.length - 2) + " more")
                            : null);
            inboxStyle.setBigContentTitle(title);
        }
        writeJSONArray(currentNotifications, CURRENT_NOTIFICATIONS);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
                .setContentText(currentNotifications[currentNotifications.length - 1])
                .setSmallIcon(MessageHistory.TYPE_TEXT.equals(type) ? R.drawable.ic_forum_white_48dp
                        : R.drawable.ic_photo_camera_white_48dp)
                .setLargeIcon(getLargeIcon(Character.toUpperCase(name.toCharArray()[0]))).setStyle(style)
                .setAutoCancel(true).setPriority(5).setContentIntent(resultPendingIntent);

        String str = context.getResources().getString(R.string.pref_key_privacy);
        mBuilder.setVisibility(context.getResources().getString(R.string.pref_value1_privacy).equals(str)
                ? NotificationCompat.VISIBILITY_SECRET
                : context.getResources().getString(R.string.pref_value2_privacy).equals(str)
                        ? NotificationCompat.VISIBILITY_PRIVATE
                        : NotificationCompat.VISIBILITY_PUBLIC);

        str = context.getResources().getString(R.string.pref_key_vibrate);
        if (defaultSharedPreferences.getBoolean(str, true))
            mBuilder.setVibrate(new long[] { 800, 500, 800, 500 });

        str = context.getResources().getString(R.string.pref_key_led);
        if (defaultSharedPreferences.getBoolean(str, true))
            mBuilder.setLights(Color.BLUE, 500, 500);

        str = defaultSharedPreferences.getString(context.getResources().getString(R.string.pref_key_ringtone),
                "");
        mBuilder.setSound("".equals(str) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
                : Uri.parse(str));

        nm.notify(NOTIFICATION_ID, mBuilder.build());
        str = context.getResources().getString(R.string.pref_key_banner);
        if (!defaultSharedPreferences.getBoolean(str, true)) {
            try {
                Thread.sleep(1500);
            } catch (InterruptedException e) {
            }
            reset();
        }
    }
}

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

private Notification preAPI16() {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setTicker(title)
            .setContentText(subtitle).setAutoCancel(true)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(pendingIntent);
    return notificationBuilder.build();
}

From source file:com.preguardia.app.notification.MyGcmListenerService.java

private void showMedicNotification(String title, String message, String consultationId) {
    // Prepare intent which is triggered if the notification is selected
    Intent intent = new Intent(this, ApproveConsultationActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.MEDIC_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_logo).setContentTitle(title).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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