Example usage for android.app Notification DEFAULT_SOUND

List of usage examples for android.app Notification DEFAULT_SOUND

Introduction

In this page you can find the example usage for android.app Notification DEFAULT_SOUND.

Prototype

int DEFAULT_SOUND

To view the source code for android.app Notification DEFAULT_SOUND.

Click Source Link

Document

Use the default notification sound.

Usage

From source file:townley.stuart.app.android.trekkinly.AlertClass.java

private void createNotification(Context context, String title, String text, String alert) {
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivityTrekkly.class), 0);
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setTicker(alert)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(text)
            .setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true);

    notification.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, notification.build());

}

From source file:com.nkc.education.service.NotificationHelper.java

/**
 * Basic Text Notification for Task Butler, using NotificationCompat
 *
 * @param context/*from w  w w.  j  ava2s .  co m*/
        
 */
public void sendBasicNotification(Context context, Task task) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean vibrate = prefs.getBoolean(AppConfig.VIBRATE_ON_ALARM, true);
    int alarmInterval;
    int alarmUnits;

    if (task.hasFinalDateDue()) {
        alarmInterval = Integer.parseInt(prefs.getString(AppConfig.ALARM_TIME, AppConfig.DEFAULT_ALARM_TIME));
        alarmUnits = Calendar.MINUTE;
    } else {
        alarmInterval = Integer
                .parseInt(prefs.getString(AppConfig.REMINDER_TIME, AppConfig.DEFAULT_REMINDER_TIME));
        alarmUnits = Calendar.HOUR_OF_DAY;
    }

    Calendar next_reminder = GregorianCalendar.getInstance();
    next_reminder.add(alarmUnits, alarmInterval);

    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setContentIntent(getPendingIntent(context, task.getID()))
            .setContentInfo(Task.PRIORITY_LABELS[task.getPriority()]).setContentTitle(task.getName())
            .setContentText(task.getDetail())
            .setDefaults(vibrate ? Notification.DEFAULT_ALL
                    : Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_exam_name
                    : R.drawable.ic_exam_name)
            .setLargeIcon(bitmap).setTicker(task.getName()).setPriority(Notification.PRIORITY_MAX)
            .setColor(Color.argb(255, 21, 149, 196)).setWhen(System.currentTimeMillis());

    @SuppressWarnings("deprecation")
    Notification notification = builder.getNotification();
    NotificationManager notificationManager = getNotificationManager(context);
    notificationManager.notify(task.getID(), notification);
}

From source file:edu.worcester.cs499summer2012.service.NotificationHelper.java

/**
 * Basic Text Notification for Task Butler, using NotificationCompat
 * @param context //from   ww w.j  av  a  2  s.  c om
 * @param id id of task, call task.getID() and pass it to this parameter
 */
public void sendBasicNotification(Context context, Task task) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean vibrate = prefs.getBoolean(SettingsActivity.VIBRATE_ON_ALARM, true);
    int alarmInterval;
    int alarmUnits;

    if (task.hasFinalDateDue()) {
        alarmInterval = Integer
                .parseInt(prefs.getString(SettingsActivity.ALARM_TIME, SettingsActivity.DEFAULT_ALARM_TIME));
        alarmUnits = Calendar.MINUTE;
    } else {
        alarmInterval = Integer.parseInt(
                prefs.getString(SettingsActivity.REMINDER_TIME, SettingsActivity.DEFAULT_REMINDER_TIME));
        alarmUnits = Calendar.HOUR_OF_DAY;
    }

    Calendar next_reminder = GregorianCalendar.getInstance();
    next_reminder.add(alarmUnits, alarmInterval);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setContentIntent(getPendingIntent(context, task.getID()))
            .setContentInfo(Task.PRIORITY_LABELS[task.getPriority()]).setContentTitle(task.getName())
            .setContentText(DateFormat.format("'Next reminder at' h:mmaa", next_reminder))
            .setDefaults(vibrate ? Notification.DEFAULT_ALL
                    : Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_notification
                    : R.drawable.ic_notification_deprecated)
            .setTicker(task.getName()).setWhen(System.currentTimeMillis());
    @SuppressWarnings("deprecation")
    Notification notification = builder.getNotification();
    NotificationManager notificationManager = getNotificationManager(context);
    notificationManager.notify(task.getID(), notification);
}

From source file:org.svij.taskwarriorapp.services.NotificationService.java

public int onStartCommand(Intent intent, int flags, int startId) {

    TaskDatabase data = new TaskDatabase(getApplicationContext());
    ArrayList<String> tasks = data.getDueTasks();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    if (prefs.getBoolean("notifications_due_task", true)) {

        if (tasks.size() > 0) {
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle(tasks.size() + getResources().getString(R.string.notification_title))
                    .setContentText(//from   ww  w  .j a v  a2  s  .c o m
                            tasks.size() + getResources().getString(R.string.notification_content_text));
            builder.setAutoCancel(true);

            String alarms = prefs.getString("notifications_due_task_ringtone", "default ringtone");
            Uri uri = Uri.parse(alarms);

            builder.setSound(uri);

            if (prefs.getBoolean("notifications_due_task_vibrate", true)) {
                builder.setDefaults(Notification.DEFAULT_ALL);
            } else {
                builder.setDefaults(Notification.DEFAULT_SOUND);
            }

            Intent resultIntent = new Intent(this, TasksActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(TasksActivity.class);
            stackBuilder.addNextIntent(resultIntent);

            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            builder.setContentIntent(resultPendingIntent);

            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            notificationManager.notify(0, builder.build());
        }
    }

    return super.onStartCommand(intent, flags, startId);
}

From source file:org.androidpn.client.SerivceManager.Notifier.java

public void notify(String notificationId, String apiKey, String title, String message, String uri) {
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
        // Show the toast
        if (isNotificationToastEnabled()) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }/*from w ww .j a  v  a  2 s .c om*/

        // PNNotification
        int ntfyDefaults = Notification.DEFAULT_LIGHTS;
        if (isNotificationSoundEnabled()) {
            ntfyDefaults |= Notification.DEFAULT_SOUND;
        }
        if (isNotificationVibrateEnabled()) {
            ntfyDefaults |= Notification.DEFAULT_VIBRATE;
        }

        Intent intent;
        //launch mainactivity
        if (uri == null || uri.length() <= 0) {
            intent = new Intent(context, MainActivity.class);
        } else {
            intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(uri));
        }
        /*
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, title);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        intent.putExtra(Constants.NOTIFICATION_URI, uri);*/
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        Notification.Builder notification = new Notification.Builder(context).setContentTitle(title)
                .setContentText(message).setSmallIcon(getNotificationIcon()).setDefaults(ntfyDefaults)
                .setContentIntent(contentIntent)
                //.setLargeIcon(R.drawable.notification)
                .setWhen(System.currentTimeMillis()).setTicker(message);

        notify(notification);

        //notification.flags |= PNNotification.FLAG_AUTO_CANCEL;

        //            Intent intent;
        //            if (uri != null
        //                    && uri.length() > 0
        //                    && (uri.startsWith("http:") || uri.startsWith("https:")
        //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
        //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        //            } else {
        //                String callbackActivityPackageName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
        //                String callbackActivityClassName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
        //                intent = new Intent().setClassName(callbackActivityPackageName,
        //                        callbackActivityClassName);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            }

        //notification.setLatestEventInfo(context, title, message,
        //        contentIntent);
        //notificationManager.notify(random.nextInt(), notification);

        //            Intent clickIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLICKED);
        //            clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title);
        //            clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        //            clickIntent.putExtra(Constants.NOTIFICATION_URI, uri);
        //            //        positiveIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clickPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clickIntent, 0);
        //
        //            notification.setLatestEventInfo(context, title, message,
        //                    clickPendingIntent);
        //
        //            Intent clearIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLEARED);
        //            clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            //        negativeIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clearPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clearIntent, 0);
        //            notification.deleteIntent = clearPendingIntent;
        //
        //            notificationManager.notify(random.nextInt(), notification);

    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }

    datasource = new PNNotificationDataSource(context);
    datasource.open();
    datasource.createNotification(title, message, uri);
    datasource.close();

    //Update the list view

    if (MainActivity.instance != null) {
        MainActivity.instance.resetList();
    }

}

From source file:com.example.bomber.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, EmergenciasCurso.class),
            0);// www . j a v  a2 s.com

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.emergencia).setContentTitle("Notificacion")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setContentInfo("4").setTicker("Alerta emergencia en progreso!!")
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
            .setAutoCancel(true);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:grk.impala.GCMIntentService.java

private static void generateNotification(Context context, String message) {
    Intent notificationIntent = null;//from   w w  w . j ava 2s.  c  om
    if (PrefUtil.getLoggedIn(context)) {
        if (PrefUtil.getUserType(context) == 2) {
            notificationIntent = new Intent(context, StatusActivity.class);
        } else {
            notificationIntent = new Intent(context, NotificationActivity.class);
        }
    } else {
        notificationIntent = new Intent(context, SplashActivity.class);
    }

    PendingIntent contentIntent = TaskStackBuilder.create(context)
            .addNextIntentWithParentStack(notificationIntent)
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(context.getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setAutoCancel(true).setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);

    mBuilder.setContentIntent(contentIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.cancelAll();
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:net.bither.util.SystemUtil.java

public static void nmNotifyDefault(NotificationManager nm, Context context, int notifyId, Intent intent,
        String title, String contentText, int iconId) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(iconId);/* w  w w  . ja v a2s . c o m*/
    builder.setContentText(contentText);
    builder.setContentTitle(title);

    builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));

    builder.setWhen(System.currentTimeMillis());
    Notification notification = null;

    notification = builder.build();
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0xFF84E4FA;
    notification.ledOnMS = 3000;
    notification.ledOffMS = 2000;
    nm.notify(notifyId, notification);

}

From source file:org.addhen.birudo.ui.widget.BuildStateNotification.java

public void setNotification(Context context, @Vibrate BooleanPreference vibrate, @Sound BooleanPreference sound,
        String message, JenkinsBuildInfoJsonModel.Result result, long duration) {

    Intent pendingIntent = new Intent(context, MainActivity.class);
    PendingIntent viewPendingIntent = PendingIntent.getActivity(context, 0, pendingIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_view,
            context.getString(R.string.open), viewPendingIntent).build();
    Bitmap bitmap;/*from   w  ww  .ja  v a2 s  . com*/
    if (result == JenkinsBuildInfoJsonModel.Result.SUCCESS) {
        Drawable drawable = context.getResources().getDrawable(R.drawable.success_notification_bg);
        bitmap = AppUtil.drawableToBitmap(drawable);
    } else {
        Drawable drawable = context.getResources().getDrawable(R.drawable.fail_notification_bg);
        bitmap = AppUtil.drawableToBitmap(drawable);
    }

    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
    wearableExtender.setBackground(bitmap);

    final String timeDuration = String.format("%s ", AppUtil.formattedDuration(duration));

    NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
    bigStyle.bigText(context.getString(R.string.build_status, result.name(), timeDuration));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_stat_ic_stat_notify_post)
            .setContentTitle(context.getString(R.string.new_message_from_jenkins)).setContentText(message)
            .setContentIntent(viewPendingIntent).extend(wearableExtender.addAction(action)).setStyle(bigStyle);
    Notification notify = notificationBuilder.build();

    if (vibrate.get()) {
        notify.defaults |= Notification.DEFAULT_VIBRATE;
    }

    if (sound.get()) {
        notify.defaults |= Notification.DEFAULT_SOUND;
    }

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notify);
}

From source file:org.ancode.alivelib.notification.AliveNotification.java

private Notification createBuilder(Bitmap largeIcon, int smallIcon, CharSequence contentTitle,
        CharSequence contentText, CharSequence ticker, long when, boolean onGoing, boolean autoCancel,
        boolean onlyAlertOnce, PendingIntent pendingIntent) {
    NotificationCompat.Builder nb = new NotificationCompat.Builder(HelperConfig.CONTEXT);
    nb.setDefaults(Notification.DEFAULT_SOUND);
    nb.setContentTitle(contentTitle);/*from  ww  w.jav  a  2s. co m*/
    nb.setContentText(contentText);
    nb.setTicker(ticker);
    nb.setWhen(when);
    nb.setOngoing(onGoing);
    //heads up http://www.jianshu.com/p/4d76b2bc8784
    //nb.setFullScreenIntent(pendingIntent, true);
    nb.setContentIntent(pendingIntent);

    nb.setAutoCancel(autoCancel);
    nb.setOnlyAlertOnce(onlyAlertOnce);
    nb.setSmallIcon(smallIcon);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        nb.setLargeIcon(largeIcon);
    }
    return nb.build();
}