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.windroilla.invoker.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w w w. j  av  a2s .  c o 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);/*from   w w  w  .j av  a  2  s.co m*/

        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  a 2s . co 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  w  w.  ja  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.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.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  w  w w . j a  v a2  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 {//from w  w w .  ja  v  a 2  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);
    }
}

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);
        }//from w  w  w .j a va  2  s  .  c o m
    }
    uri = alert;
}

From source file:com.QuarkLabs.BTCeClient.MainActivity.java

@Override
public void makeNotification(int id, String message) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_bitcoin_sign)
            .setContentTitle(getResources().getString(R.string.app_name)).setContentText(message);

    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:com.firescar96.nom.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void Notify(String notificationTitle, String notificationMessage, Bundle data, int id,
        boolean annoy) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(thisService)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle)
            .setContentText(notificationMessage).setAutoCancel(true);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(thisService, MainActivity.class);
    resultIntent.putExtras(data);//w  ww  .ja  v a  2s .  c  o m

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(thisService);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    if (annoy) {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
        long[] pattern = { 50, 100, 10, 100, 10, 200 };
        mBuilder.setVibrate(pattern);
    }
    NotificationManager mNotificationManager = (NotificationManager) thisService
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:com.touristadev.tourista.services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from w ww  . j a  va 2  s  .c  o  m*/
public void sendNotification(String title, String messageBody, BookedPackage fbnot) {

    Intent intent2 = new Intent(getApplicationContext(), RequestActivity.class);
    intent2.putExtra("numberOfPerson", fbnot.getNumOfPeople());
    intent2.putExtra("packageId", fbnot.getPackageId());
    intent2.putExtra("reserveDate", fbnot.getReserveDate());

    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(RequestActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(intent2);

    PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_notification_marker).setContentTitle(title).setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(contentIntent);

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

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

}