Example usage for android.app Notification DEFAULT_VIBRATE

List of usage examples for android.app Notification DEFAULT_VIBRATE

Introduction

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

Prototype

int DEFAULT_VIBRATE

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

Click Source Link

Document

Use the default notification vibrate.

Usage

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. j  av a 2  s  .  co m*/
    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.enbyted.android.zseinfo.view.NotificationManager.java

public static void notifyNewReplacementForMe() {

    if (builderNewReplacements == null) {
        builderNewReplacements = new NotificationCompat.Builder(getContext());
        builderNewReplacements.setSmallIcon(R.drawable.ic_launcher);
    }//from   w  ww. j ava 2s . com

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.putExtra("tab", "TAB_REPLACEMENTS");
    resultIntent.putExtra("my_class", true);
    resultIntent.putExtra("TYPE", ID_NEW_REPLACEMENT);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());

    stackBuilder.addNextIntent(resultIntent);

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

    builderNewReplacements.setContentIntent(resultPendingIntent);

    builderNewReplacements.setContentTitle("Nowe zastpstwo!");
    builderNewReplacements.setContentText("Kliknij aby zobaczy nowe zastpstwa dla twojej klasy.");
    builderNewReplacements.setDefaults(Notification.DEFAULT_VIBRATE);

    getManager().notify(ID_NEW_REPLACEMENT, builderNewReplacements.build());
}

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);/* w  w  w. j a  v a  2 s  . c om*/

    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:com.example.mego.adas.utils.NotificationUtils.java

/**
 * Helper Method to create and display waring notification
 *
 * @param context/*from ww  w . j av a2  s  .  co m*/
 * @param notificationBody the content text with in notification
 */
public static void showWarningNotification(Context context, String notificationBody) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(largeIcon(context)).setContentTitle(context.getString(R.string.notification_waring))
            .setContentText(notificationBody)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody))
            .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent(context)).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

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

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

From source file:grk.impala.GCMIntentService.java

private static void generateNotification(Context context, String message) {
    Intent notificationIntent = null;/*from   www.  ja  v  a  2  s .c  o m*/
    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: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 va 2 s . c o  m

        // 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.ubikod.urbantag.NotificationHelper.java

/**
 * Notify a new content(place or event)/*from w  ww  .  j a  v  a2  s  .c o m*/
 * @param contentId Id of content
 * @param content Content name
 * @param placeName Place name it will happend
 * @param type type of notification
 */
private void notify(int contentId, String content, String placeName, int type) {

    String title = content;
    String text = placeName;
    int icon = content_icon;
    if (type == NEW_PLACE_NOTIF) {
        title = placeName;
        text = mContext.getResources().getString(R.string.new_place);
        icon = place_icon;
    }
    /* Modify intent to transmit id */
    Intent intent;
    intent = new Intent(mContext, ContentViewerActivity.class);
    intent.putExtra(ContentViewerActivity.CONTENT_ID, contentId);

    /* Add the from notification extra info and create the pending intent */
    intent.putExtra(FROM_NOTIFICATION, type);
    PendingIntent activity = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    /* Create notification */
    Notification newNotification = new NotificationCompat.Builder(mContext).setSmallIcon(icon)
            .setContentText(text).setContentTitle(title).setContentIntent(activity).setTicker(title)
            .getNotification();

    // newNotification.contentView = contentView;
    newNotification.flags |= Notification.FLAG_AUTO_CANCEL;
    newNotification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;

    /* notify */
    mNotificationManager.notify(type, newNotification);
}

From source file:com.sakisds.icymonitor.GcmBroadcastReceiver.java

private void sendNotification(String name, String computerName, int id, String value) {
    NotificationManager mNotificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
            new Intent(mContext, ConnectionActivity.class), 0);

    String text;//from   w w w .java2 s  . c o  m
    if (name.equals("IcyTestNotification")) {
        text = "Test notification received.";
        name = "Test";
    } else {
        text = "Sensor is currently at " + value;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_notification).setContentTitle(computerName + ": " + name)
            .setContentText(text)
            .setSound(Uri.parse(mSettings.getString(mRes.getString(R.string.key_notification),
                    Settings.System.DEFAULT_NOTIFICATION_URI.toString())));

    if (mSettings.getBoolean(mRes.getString(R.string.key_vibrate), true)) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    if (mSettings.getBoolean(mRes.getString(R.string.key_lights), true)) {
        mBuilder.setLights(Color.RED, 1000, 1000);
    }

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

From source file:edu.cmu.cylab.starslinger.util.NotificationBroadcastReceiver.java

@SuppressWarnings("deprecation")
public static void doUnseenMessagesNotification(Context ctx, int msgCount, boolean giveNotificationFeedback)
        throws OutOfMemoryError {
    long when = System.currentTimeMillis(); // notification time

    // To create a status bar notification:
    // Get a reference to the NotificationManager:
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) ctx.getSystemService(ns);

    String tickerText = ctx.getString(R.string.title_NotifyFileAvailable);

    String contentTitle = String.format(Locale.getDefault(), "%s (%d)", ctx.getString(R.string.app_name),
            msgCount);/*  w w  w .ja  va 2  s . co  m*/
    String contentText = String.format(ctx.getString(R.string.label_ClickForNMsgs), msgCount);

    Intent intent = makeMessagesNotificationIntent(ctx);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // the next two lines initialize the Notification, using the
    // configurations above
    int visibleMsgCount = msgCount != 1 ? msgCount : 0;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)//
            .setContentIntent(contentIntent)//
            .setSmallIcon(R.drawable.ic_stat_notify_msg)//
            .setTicker(tickerText)//
            .setWhen(when)//
            .setAutoCancel(true)//
            .setContentTitle(contentTitle)//
            .setContentText(contentText)//
            .setNumber(visibleMsgCount)//
            .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    try {
        builder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher));
    } catch (OutOfMemoryError e) {
        // ignore icon when out of memory
    }

    // set notification alerts based on user preferences
    int defaults = 0;
    if (SafeSlingerPrefs.getNotificationVibrate() && giveNotificationFeedback) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }
    String ringtoneStr = SafeSlingerPrefs.getNotificationRingTone();
    builder.setSound(
            TextUtils.isEmpty(ringtoneStr) || !giveNotificationFeedback ? null : Uri.parse(ringtoneStr));
    defaults |= Notification.DEFAULT_LIGHTS;
    builder.setDefaults(defaults);

    Notification n = builder.build();

    // total messages seen...
    n.number = visibleMsgCount; // API <11
    if (msgCount != 1) {
        // cancel old one since we want to avoid the "1" when updating
        // number
        nm.cancel(HomeActivity.NOTIFY_NEW_MSG_ID);
    }

    // Pass the Notification to the NotificationManager:
    nm.notify(HomeActivity.NOTIFY_NEW_MSG_ID, n);
}

From source file:com.etime.TimeAlarmService.java

/**
 * Send a notification to the user with the message 'notificationString'
 * @param notifcationString    The message to notify the user with.
 *//*from  ww  w  . j av  a 2  s . c  o  m*/
private void notification(String notifcationString) {
    CharSequence from = "ETime";
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notif = new Notification(R.drawable.icon, notifcationString, System.currentTimeMillis());

    notif.flags |= Notification.DEFAULT_LIGHTS;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

    notif.setLatestEventInfo(this, from, notifcationString, contentIntent);
    nm.notify("ETime", APP_ID, notif);
}