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:gcm.GcmMessageHandler.java

private void createNotification(String title, String body) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
            | Notification.DEFAULT_SOUND | Notification.FLAG_AUTO_CANCEL;

    Intent notificationIntent = new Intent(context, ConversationActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(body)
            .setDefaults(defaults).setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setContentIntent(contentIndent).setAutoCancel(true);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

From source file:org.linphone.compatibility.ApiElevenPlus.java

@SuppressWarnings("deprecation")
public static Notification createMessageNotification(Context context, int msgCount, String msgSender,
        String msg, Bitmap contactIcon, PendingIntent intent) {
    String title;//  ww w.j a v a 2  s. c om
    if (msgCount == 1) {
        title = msgSender;
    } else {
        title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
    }

    Notification notif = new Notification.Builder(context).setContentTitle(title).setContentText(msg)
            .setContentIntent(intent).setSmallIcon(R.drawable.chat_icon_over).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setWhen(System.currentTimeMillis()).setLargeIcon(contactIcon).getNotification();

    return notif;
}

From source file:es.ugr.swad.swadroid.gui.AlertNotificationFactory.java

public static NotificationCompat.Builder createAlertNotificationBuilder(Context context, String contentTitle,
        String contentText, String ticker, PendingIntent pendingIntent, int smallIcon, int largeIcon,
        boolean alertSignals, boolean autocancel, boolean ongoing, boolean onlyAlertOnce) {

    int flags = 0;

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context).setAutoCancel(autocancel)
            .setSmallIcon(smallIcon)//from  w  w w  . j  a v a  2 s. c  om
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), largeIcon))
            .setContentTitle(contentTitle).setContentText(contentText).setTicker(ticker).setOngoing(ongoing)
            .setOnlyAlertOnce(onlyAlertOnce).setWhen(System.currentTimeMillis());
    //.setLights(Color.GREEN, 500, 500);

    //Launch activity on alert click
    if (pendingIntent != null) {
        notifBuilder.setContentIntent(pendingIntent);
    }

    //Add sound, vibration and lights
    if (alertSignals) {
        if (Preferences.isNotifSoundEnabled()) {
            flags |= Notification.DEFAULT_SOUND;
        } else {
            notifBuilder.setSound(null);
        }

        if (Preferences.isNotifVibrateEnabled()) {
            flags |= Notification.DEFAULT_VIBRATE;
        }

        if (Preferences.isNotifLightsEnabled()) {
            flags |= Notification.DEFAULT_LIGHTS;
        }
    }

    notifBuilder.setDefaults(flags);

    return notifBuilder;
}

From source file:com.odoo.util.ONotificationHelper.java

@SuppressWarnings("deprecation")
public void showNotification(Context context, String title, String subtitle, String authority, int icon) {
    mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification(icon, title, System.currentTimeMillis());
    if (notificationIntent != null) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, title, subtitle, pendingIntent);
    }//from  w ww .  j  a  v a2  s  .co  m
    mNotifyManager.notify(0, notification);
}

From source file:com.codemobiles.util.CMNotification.java

public static void notify(final Context ctx, final int iconResID, final String remote_image_url,
        final String title, final String desc, final Class<?> receiver) {
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override//from  w  ww  . j  a  v a  2 s. c om
        public void run() {
            try {
                remote_picture = BitmapFactory
                        .decodeStream((InputStream) new URL(remote_image_url).getContent());
                // remote_picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher);
            } catch (IOException e) {
                e.printStackTrace();
            }

            handler.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    mNotificationManager = (NotificationManager) ctx
                            .getSystemService(Context.NOTIFICATION_SERVICE);

                    Notification noti = setNormalNotification(ctx, iconResID, remote_picture, title, desc,
                            receiver);
                    // Notification noti = setBigTextStyleNotification(ctx);
                    noti.defaults |= Notification.DEFAULT_LIGHTS;
                    noti.defaults |= Notification.DEFAULT_VIBRATE;
                    noti.defaults |= Notification.DEFAULT_SOUND;
                    noti.defaults |= Notification.FLAG_AUTO_CANCEL;
                    noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

                    final int notificationID = new Random().nextInt();
                    noti.when = System.currentTimeMillis() + 1000 * 60;
                    mNotificationManager.notify(notificationID, noti);
                }
            });

        }
    }).start();

}

From source file:es.ugr.swad.swadroid.gui.AlertNotification.java

public static void alertNotif(Context context, int notifAlertId, String contentTitle, String contentText,
        String ticker, Intent activity) {

    //Obtain a reference to the notification service
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager notifManager = (NotificationManager) context.getSystemService(ns);

    //Configure the alert
    int defaults = 0;

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_launcher_swadroid)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher_swadroid))
            .setContentTitle(contentTitle).setContentText(contentText).setTicker(ticker)
            .setWhen(System.currentTimeMillis());
    //.setLights(Color.GREEN, 500, 500);

    //Launch activity on alert click
    if (activity != null) {
        PendingIntent notificationsPendingIntent = PendingIntent.getActivity(context, 0, activity,
                Intent.FLAG_ACTIVITY_NEW_TASK);
        notifBuilder.setContentIntent(notificationsPendingIntent);
    }//  ww  w  . j  a  v  a 2s. co  m

    //Add sound, vibration and lights
    if (Preferences.isNotifSoundEnabled()) {
        defaults |= Notification.DEFAULT_SOUND;
    } else {
        notifBuilder.setSound(null);
    }

    if (Preferences.isNotifVibrateEnabled()) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    if (Preferences.isNotifLightsEnabled()) {
        defaults |= Notification.DEFAULT_LIGHTS;
    }

    notifBuilder.setDefaults(defaults);

    //Create alert
    Notification notif = notifBuilder.build();

    //Send alert
    notifManager.notify(notifAlertId, notif);
}

From source file:enterprayz.megatools.NotificationBuilder.java

private static void createNotification(Context context, Class activity, int id, int largeIcoRes,
        int smallIcoRes, String title, String subTitle, String ticket, boolean canCancel) {
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), largeIcoRes);

    Intent intent = new Intent(context, activity);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, FLAG_ACTIVITY_NEW_TASK);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setContentText(subTitle).setContentTitle(title).setSmallIcon(smallIcoRes).setOngoing(!canCancel)
            .setTicker(ticket).setLargeIcon(largeIcon)
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
            .setContentIntent(pendingIntent);

    Notification notification = notificationBuilder.build();

    notificationManager.notify(id, notification);
}

From source file:fr.paug.droidcon.ui.debug.actions.ShowSessionNotificationDebugAction.java

@Override
public void run(Context context, Callback callback) {

    Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__"));

    PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);

    //= PendingIntent.getActivity(context, 0, mapIntent, 0);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
            .setContentTitle("test notification").setContentText("yep, this is a test")
            .setTicker("hey, you got a test")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi)
            .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true);

    NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder)
            .setBigContentTitle(//from  w ww  .  jav a 2 s .  c  o m
                    context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1));

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(32534, richNotification.build());

}

From source file:nu.shout.shout.chat.ChatNotifier.java

private void applySettings() {
    int defaults = 0;
    if (this.prefs.getBoolean("noti_sound", true))
        defaults |= Notification.DEFAULT_SOUND;
    if (this.prefs.getBoolean("noti_vibrate", true))
        defaults |= Notification.DEFAULT_VIBRATE;
    if (this.prefs.getBoolean("noti_light", true))
        defaults |= Notification.DEFAULT_LIGHTS;
    this.builder.setDefaults(defaults);
}

From source file:com.mattermost.gcm.GcmMessageHandler.java

private void createNotification(boolean doAlert) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    if (doAlert) {
        defaults = defaults | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
    }//  w w w.j a v  a2s  . c o m

    Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, NotificationDismissReceiver.class), 0);

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

    if (channelIdToNotification.size() == 0) {
        mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES).setDefaults(defaults)
            .setContentIntent(contentIndent).setDeleteIntent(deleteIntent).setAutoCancel(true);

    if (channelIdToNotification.size() == 1) {
        Bundle data = channelIdToNotification.entrySet().iterator().next().getValue();
        String body = data.getString("message");
        mBuilder.setContentTitle("Mattermost").setContentText(body)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body));
    } else {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        String summaryTitle = String.format("Mattermost (%d)", channelIdToNotification.size());
        mBuilder.setContentTitle(summaryTitle);

        for (Bundle data : channelIdToNotification.values()) {
            style.addLine(data.getString("message"));
        }

        style.setBigContentTitle(summaryTitle);
        mBuilder.setStyle(style);
    }

    mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}