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.alivenet.dmvtaxi.FcmUtil.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  w  w  . j a v  a  2s .  c o m
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void sendNotification(String message) {
    SharedPreference sharedPreference = new SharedPreference();

    if (splitnotifiaction_flag) {
        intent = new Intent(this, AcceptNotificationUIwork.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
    } else {

        intent = new Intent(this, DeashboardActivity.class);
        if (flag == true) {
            intent.putExtra("ridedriverInfo", MyApplication.rideDriverComplete);
            intent.putExtra("flag", flag);
        }
        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("Notification").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.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java

private void sendNotificationForChargedNurse(String message) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction("chargedNurse");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Intent intentAccept = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT);
    ////  ww w .  j  a  v  a2 s. c om
    Intent intentDecline = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent).setAutoCancel(true);

    notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
    notificationBuilder.setAutoCancel(true);

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

    notificationManager.notify((int) new Date().getTime(), notificationBuilder.build());

}

From source file:com.zaparound.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *///from ww  w . ja v  a2s . c  o  m
private void sendAcceptNotification(String messagetitle, String messageBody) {
    Intent intent = new Intent(this, LandingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("CHATTAB_POSITION", 2);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0)
            .setAutoCancel(true).setContentTitle(messagetitle)
            //.setNumber(++count)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            //.setSubText("\n "+count+" new messages\n")
            .setContentIntent(pendingIntent)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo))
            .setContentText(messageBody).build();

    NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notification);
}

From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java

private Notification getNotification(String content) {
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    Notification.Builder builder = new Notification.Builder(this);
    builder.setContentTitle("EasyPark Notification");
    builder.setContentText(content);// w  w  w .j av  a 2 s .c  o m
    builder.setSmallIcon(R.drawable.ic_car);
    builder.setPriority(BIND_IMPORTANT);
    builder.setSound(soundUri);

    // return builder.build();

    return new Notification.BigTextStyle(builder).bigText(content).build();
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  ww. j a va2  s . c  o m
 */
private void sendNotification(Context context, String from, String message) {
    /*
    Intent intent = new Intent(context, DevToolActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);
    */

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.shortcut_pkg).setContentTitle("Uninstalled").setContentText(message)
            .setAutoCancel(true);
    //       .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
    //       .setLights(Color.RED, 3000, 3000)
    //       .setSound(defaultSoundUri)
    //       .setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
    //       .setContentIntent(pendingIntent);

    // <uses-permission android:name="android.permission.VIBRATE" />

    Notification note = notificationBuilder.build();
    note.defaults |= Notification.DEFAULT_VIBRATE;
    note.defaults |= Notification.DEFAULT_SOUND;
    note.defaults |= Notification.DEFAULT_LIGHTS;

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

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

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

public void notifyNewsletter(String title, 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, 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.ja v  a 2 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:io.coldstart.android.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void SendInboxStyleNotification(String alertCount, String alertTime, String hostname,
        String payloadDetails) {//from  ww  w.j  a v a 2  s. c  om
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    String Line1 = "", Line2 = "", Line3 = "", Line4 = "", Line5 = "";
    String[] separatedLines = payloadDetails.split("\n");

    int payloadLength = separatedLines.length;
    if (payloadLength > 5)
        payloadLength = 5;

    for (int i = 0; i < payloadLength; i++) {
        try {
            switch (i) {
            case 0: {
                Line1 = separatedLines[i];
            }
                break;

            case 1: {
                Line2 = separatedLines[i];
            }
                break;

            case 2: {
                Line3 = separatedLines[i];
            }
                break;

            case 3: {
                Line4 = separatedLines[i];
            }
                break;

            case 4: {
                Line5 = separatedLines[i];
            }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Notification notification = new Notification.InboxStyle(
            new Notification.Builder(this).setContentTitle("SNMP trap received")
                    .setContentText(Line1 + " " + Line2 + "...").setSmallIcon(R.drawable.ic_stat_alert)
                    .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri)
                    .setPriority(Notification.PRIORITY_MAX).setTicker("New SNMP traps have been received")
                    .setContentIntent(PendingIntent.getActivity(this, 0,
                            new Intent(this, TrapListActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                                    .putExtra("forceRefresh", true),
                            0))).setBigContentTitle("New SNMP traps have been received")
                                    .setSummaryText("Launch ColdStart.io to Manage These Events").addLine(Line1)
                                    .addLine(Line2).addLine(Line3).addLine(Line4).build();

    notification.defaults |= Notification.DEFAULT_SOUND;

    mNM.notify(43523, notification);
}

From source file:com.weddingsingers.wsapp.fcm.MyFirebaseMessagingService.java

private void sendNotification(ChatMessage m) {

    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(SplashActivity.EXTRA_FRAGNAME, ChattingActivity.class);

    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.drawable.manifest_ic_wedding_singers_512).setContentTitle("FCM Message")
            .setContentText(m.getSender().getName() + "?  - " + m.getMessage())
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

    /*Intent intent = new Intent(this, SplashActivity.class);
    intent.putExtra(ChattingActivity.EXTRA_USER, m.getSender());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512)
        .setTicker("Chat Message")//from   w w  w.j  a v  a  2s. c om
        .setContentTitle("  ")
        .setContentText(m.getSender().getName() + "?  - " + m.getMessage())
        .setAutoCancel(true)
        .setDefaults(NotificationCompat.DEFAULT_ALL)
        .setContentIntent(pendingIntent);
            
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            
    notificationManager.notify(0 *//* ID of notification *//*, notificationBuilder.build());*/
}

From source file:com.renjunzheng.vendingmachine.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w  w w .jav a2  s  .  co m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, VMSelection.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.icon_w).setContentTitle("Ultimate Vending Machine").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
            .setColor(getColor(R.color.notification_color));

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

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

From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java

private void syncNotifications(Account account, SyncResult syncResult)
        throws AuthenticationException, IOException {
    final User user = AccountUtils.getUser(getContext(), account.name);
    final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()),
            account, getContext());/*from  ww w .j  a v a  2  s. co  m*/
    final Gson gson = GsonUtils.getGson();
    final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class);
    if (notifications == null) {
        syncResult.stats.numParseExceptions++;
        LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true);
        return;
    }
    ArrayList<String> fetchedNotCodes = new ArrayList<String>();
    ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>();
    for (Notification not : notifications) {
        final ContentValues values = new ContentValues();
        values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not));
        fetchedNotCodes.add(not.getCode());
        if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values,
                SigarraContract.Notifcations.UPDATE_NOTIFICATION,
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) {
            values.put(SigarraContract.Notifcations.CODE, account.name);
            values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode());
            values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW);
            values.put(SigarraContract.Notifcations.CODE, account.name);
            bulkValues.add(values);
        }

    }
    // inserting the values
    if (bulkValues.size() > 0) {
        getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI,
                bulkValues.toArray(new ContentValues[0]));
        // if the account being synced is the current active accout
        // display notification
        if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) {
            final NotificationManager mNotificationManager = (NotificationManager) getContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext());
            notBuilder.setAutoCancel(true).setOnlyAlertOnce(true)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            if (bulkValues.size() == 1) {
                final Notification notification = gson.fromJson(
                        bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT),
                        Notification.class);
                Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class)
                        .putExtra(NotificationsDescFragment.NOTIFICATION, notification);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage())
                        .setContentTitle(notification.getSubject()).setContentText(notification.getMessage())
                        .setContentIntent(notifyPendingIntent)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())
                                .setBigContentTitle(notification.getSubject())
                                .setSummaryText(notification.getMessage()));
                mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build());
            } else {
                final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size());

                Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class);
                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                // Sets a title for the Inbox style big view
                inboxStyle.setBigContentTitle(notTitle);
                // Moves events into the big view
                for (ContentValues value : bulkValues) {
                    final Notification notification = gson.fromJson(
                            value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class);
                    inboxStyle.addLine(notification.getSubject());
                }
                // Moves the big view style object into the notification
                // object.
                notBuilder.setStyle(inboxStyle);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle)
                        .setContentText("").setContentIntent(notifyPendingIntent);
                mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(),
                        notBuilder.build());
            }

        }
    }
    final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI,
            SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE,
            SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())),
            null);
    try {
        if (syncState.moveToFirst()) {
            if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) {
                // Report that we have checked the notifications
                final ContentValues values = new ContentValues();
                values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis());
                getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values,
                        SigarraContract.LastSync.PROFILE,
                        SigarraContract.LastSync.getLastSyncSelectionArgs(account.name));
            }
        }
    } finally {
        syncState.close();
    }
    ArrayList<String> notToDelete = new ArrayList<String>();
    final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI,
            new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE,
            SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null);
    try {
        if (cursor.moveToFirst()) {
            do {
                final String code = cursor.getString(0);
                if (!fetchedNotCodes.contains(code))
                    notToDelete.add(code);
            } while (cursor.moveToNext());
        } else {
            // no notifications
            getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null);
        }
    } finally {
        cursor.close();
    }
    if (notToDelete.size() > 0)
        getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI,
                SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])),
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name,
                        notToDelete.toArray(new String[0])));
    syncResult.stats.numEntries += notifications.length;
}