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:de.damdi.fitness.activity.start_training.RecoveryTimerManager.java

private synchronized void startTimer(final RecoveryTimerKind timerKind) {
    // create notification
    mNotificationBuilder = new NotificationCompat.Builder(mContext);
    mNotificationBuilder.setContentTitle(timerKind.contentTitleRunning)
            .setSmallIcon(R.drawable.icon_dumbbell_small)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), R.drawable.icon_dumbbell));

    final boolean doVibrate = mVibrationEnabled;
    final boolean doBeep = mNotificationSoundEnabled;
    int maxInSec = timerKind.timerDurationInSec;
    final int max = 10 * maxInSec;
    mSetTimer = new Timer();

    TimerTask task = new TimerTask() {
        private int counter = 0;

        @Override/* w ww.  j av a 2  s. c om*/
        public void run() {
            // update progress if still running
            if (counter < max) {
                mNotificationBuilder.setTicker(timerKind.tickerRunning);
                mNotificationBuilder.setProgress(max, counter, false);
                mNotificationBuilder.setUsesChronometer(true);
                // Displays the progress bar for the first time.
                mNotifyManager.notify(0, mNotificationBuilder.build());

                counter++;
            } else {
                mNotificationBuilder.setProgress(max, max, false);
                //mNotificationBuilder.setNumber(max);

                // change message if progress is finished
                mNotificationBuilder.setContentTitle(timerKind.contentTitleFinished);
                mNotificationBuilder.setTicker(timerKind.tickerFinished);

                // let phone vibrate (unless user disabled this feature)
                if (doVibrate) {
                    long[] vibrationPattern = { 0, 300 };
                    mNotificationBuilder.setVibrate(vibrationPattern);
                }
                // make a notification sound (unless user disabled this feature)
                if (doBeep) {
                    Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    mNotificationBuilder.setSound(defaultSound);
                }
                mNotificationBuilder.setAutoCancel(true);
                mNotifyManager.notify(RECOVERY_TIMER_NOTIFICATION_ID, mNotificationBuilder.build());
                mSetTimer.cancel();

            }

        }
    };

    long period = 100;
    long delay = 0;
    mSetTimer.scheduleAtFixedRate(task, delay, period);
}

From source file:com.fimo_pitch.main.MainActivity.java

private void makeNotification(Context context, String title, String content) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri)
            .setPriority(Notification.PRIORITY_HIGH).setContentText(content);
    Intent resultIntent = new Intent(context, MainActivity.class);
    userModel = getUserModel();// w w  w  . j a  va 2  s.c  o  m
    resultIntent.putExtra(CONSTANT.KEY_USER, userModel);
    resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true");
    TaskStackBuilder stackBuilder = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(FirstActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(ZAQ500);
    } else {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(500);
    }
}

From source file:at.flack.receiver.EMailReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from  w  w  w  .  ja  va2s.  c  o  m
    try {
        if (bundle.getString("type").equals("mail")) {
            sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (!sharedPrefs.getBoolean("notification_mail", true))
                return;
            notify = sharedPrefs.getBoolean("notifications", true);
            vibrate = sharedPrefs.getBoolean("vibration", true);
            headsup = sharedPrefs.getBoolean("headsup", true);
            led_color = sharedPrefs.getInt("notification_light", -16776961);
            boolean all = sharedPrefs.getBoolean("all_mail", true);

            if (notify == false)
                return;

            NotificationCompat.Builder mBuilder = null;
            boolean use_profile_picture = false;
            Bitmap profile_picture = null;

            String origin_name = bundle.getString("senderName").equals("") ? bundle.getString("senderMail")
                    : bundle.getString("senderName");

            try {
                profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                        ProfilePictureCache.getInstance(context).get(origin_name), 200, 200, false), 300);
                use_profile_picture = true;
            } catch (Exception e) {
                use_profile_picture = false;
            }

            Resources res = context.getResources();

            int lastIndex = bundle.getString("subject").lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(0, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                        .setColor(0xFFFF5722)
                        .setContentText(res.getString(R.string.sms_receiver_new_encrypted_mail))
                        .setAutoCancel(true);
                if (use_profile_picture && profile_picture != null) {
                    mBuilder = mBuilder.setLargeIcon(profile_picture);
                } else {
                    mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                            context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                }
            } else {

                if (bundle.getString("subject").charAt(0) == '%' && (bundle.getString("subject").length() == 10
                        || bundle.getString("subject").length() == 9)) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (bundle.getString("subject").charAt(0) == '%'
                        && bundle.getString("subject").length() >= 120
                        && bundle.getString("subject").length() < 125) {
                    if (lastIndex > 0 && Base64.isBase64(bundle.getString("subject").substring(1, lastIndex))) {
                        mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                                .setColor(0xFFFF5722)
                                .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                                .setSmallIcon(R.drawable.notification_icon).setAutoCancel(true);
                        if (use_profile_picture && profile_picture != null) {
                            mBuilder = mBuilder.setLargeIcon(profile_picture);
                        } else {
                            mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                    context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                        }
                    } else {
                        return;
                    }
                } else if (all) { // normal message
                    mBuilder = new NotificationCompat.Builder(context)
                            .setSmallIcon(R.drawable.raven_notification_icon).setContentTitle(origin_name)
                            .setColor(0xFFFF5722).setContentText(bundle.getString("subject"))
                            .setAutoCancel(true).setStyle(
                                    new NotificationCompat.BigTextStyle().bigText(bundle.getString("subject")));

                    if (use_profile_picture && profile_picture != null) {
                        mBuilder = mBuilder.setLargeIcon(profile_picture);
                    } else {
                        mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name,
                                context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200));
                    }
                } else {
                    return;
                }
            }
            // }
            Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            mBuilder.setSound(alarmSound);
            mBuilder.setLights(led_color, 750, 4000);
            if (vibrate) {
                mBuilder.setVibrate(new long[] { 0, 100, 200, 300 });
            }

            Intent resultIntent = new Intent(context, MainActivity.class);
            resultIntent.putExtra("MAIL", bundle.getString("senderMail"));

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(1,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            if (Build.VERSION.SDK_INT >= 16 && headsup)
                mBuilder.setPriority(Notification.PRIORITY_HIGH);
            if (Build.VERSION.SDK_INT >= 21)
                mBuilder.setCategory(Notification.CATEGORY_MESSAGE);

            final NotificationManager mNotificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (!MainActivity.isOnTop)
                mNotificationManager.notify(9, mBuilder.build());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java

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

private void sendNotificationForTakeBreak(String message, String fromId, String toId) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction("takeBreak");
    intent.putExtra("fromId", fromId);
    intent.putExtra("toId", toId);
    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);
    //
    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.remobile.dialogs.Notification.java

/**
 * Beep plays the default notification ringtone.
 *
 * @param count Number of times to play notification
 *//* ww  w .j  a v  a 2  s.  c  o  m*/
public void beep(final long count) {
    final Activity activity = this.cordova.getActivity();
    this.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone notification = RingtoneManager.getRingtone(activity.getBaseContext(), ringtone);

            // If phone is not set to silent mode
            if (notification != null) {
                for (long i = 0; i < count; ++i) {
                    notification.play();
                    long timeout = 5000;
                    while (notification.isPlaying() && (timeout > 0)) {
                        timeout = timeout - 100;
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                        }
                    }
                }
            }
        }
    });
}

From source file:be.ac.ucl.lfsab1509.llncampus.services.AlarmService.java

/**
 * Send an alert to the user for the event e.
 * /*from  w  w  w  .j  a  va2  s .  c  o  m*/
 * @param e
 *          Event to notify to the user.
 */
private void sendAlert(Event e) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Time currentTime = new Time();
    currentTime.setToNow();

    long nbMin = e.getBeginTime().toMillis(false) / 60L / 1000L - currentTime.toMillis(false) / 60L / 1000L;

    final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setContentTitle(e.getDetail(Event.COURSE) + " " + getString(R.string.begins_in) + " " + nbMin + " "
                    + getString(R.string.minutes))
            .setContentText(e.getDetail(Event.ROOM) + " - " + e.getDetail(Event.TITLE)).setAutoCancel(true);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    String ringtone = preferences.getString(SettingsActivity.NOTIFY_RINGTONE, null);
    if (ringtone == null) {
        notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    } else {
        notificationBuilder.setSound(Uri.parse(ringtone));
    }
    notificationManager.notify(1, notificationBuilder.build());
}

From source file:com.gsma.rcs.ri.messaging.chat.single.SingleChatIntentService.java

/**
 * Generate a notification//from  w  ww  . j  a v  a 2 s .c  om
 * 
 * @param invitation invitation
 * @param title title
 * @param message message
 * @return the notification
 */
private Notification buildNotification(PendingIntent invitation, String title, String message) {
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(invitation);
    notif.setSmallIcon(R.drawable.ri_notif_chat_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(message);
    return notif.build();
}

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

public void notifyAnnouncement(String announcement, 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, 1 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

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

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(announcement);//from   w ww.  j a v  a 2 s.  c  o  m
    notifStyle.setBigContentTitle(getString(R.string.notif_announcement_title));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_announcement_title)).setContentText(announcement)
            .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_ANNOUNCEMENT, notificationBuilder.build());
}

From source file:com.vidinoti.pixlive.PixLive.java

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;/*w  w  w .  j  a  v  a  2  s.co m*/
    }

    String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK";

    String licenseKey = null;

    try {
        ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    } catch (NullPointerException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    if (storage == null || licenseKey == null) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    VDARSDKController.startSDK(c, storage, licenseKey);

    /* Comment out to disable QR code detection */
    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() {

        @Override
        public Notification createNotification(String title, String message, String notificationID) {

            Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName());

            appIntent.putExtra("nid", notificationID);
            appIntent.putExtra("remote", false);

            PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            ApplicationInfo ai = c.getApplicationInfo();

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
                    .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off)
                    .setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
                    .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 })
                    .setLights(Color.BLUE, 500, 1500);

            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            return mBuilder.getNotification();
        }
    });
}

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

private void showPatientNotification(String title, String message, String consultationId) {
    // Prepare intent which is triggered if the notification is selected
    Intent intent = new Intent(this, ConsultationDetailsActivity.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.PATIENT_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(3, notificationBuilder.build());
}