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:com.cloverstudio.spika.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) {

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);/*from www.ja va  2s.c  o m*/
        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());
        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);
    }
}

From source file:com.smart.taxi.GcmIntentService.java

private void sendNotification(Object msg) {
    Intent intent;//from ww w .  j  av a2 s .com
    String message;
    int rid = r.nextInt(1800 - 650) + 650;
    try {
        Bundle extras = (Bundle) msg;
        String notifType = (Utils.isEmptyOrNull(extras.getString("type"))
                && extras.getString("status").equals("1")) ? "accept" : extras.getString("type");
        String journeyId = extras.getString("journey_id");
        message = extras.getString("message");

        intent = new Intent(DISPLAY_MESSAGE_ACTION);

        intent.putExtra("rid", rid);
        intent.putExtra("journeyId", journeyId);
        intent.putExtra("type", notifType);
        intent.putExtra("message", (Utils.isEmptyOrNull(message)) ? "" : message);
        getApplicationContext().sendBroadcast(intent);

    } catch (Exception ex) {
        return;
    }

    Intent notifIntent = new Intent("com.smart.taxi.beep");
    notifIntent.putExtra("msg", (Utils.isEmptyOrNull(message)) ? "Beep recevied" : message);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notifIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //Define sound URI
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.InboxStyle().addLine(msg.toString())).setContentText(message)
            .setSound(soundUri).setDefaults(Notification.DEFAULT_VIBRATE);

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

From source file:com.oliversride.wordryo.Utils.java

public static void postNotification(Context context, Intent intent, String title, String body, int id) {
    /* nextRandomInt: per this link
       http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager
       one way to avoid getting the same PendingIntent for similar
       Intents is to send a different second param each time,
       though the docs say that param's ignored.
    *///from   w w  w.j ava2s  . c  o  m
    PendingIntent pi = null == intent ? null
            : PendingIntent.getActivity(context, Utils.nextRandomInt(), intent, PendingIntent.FLAG_ONE_SHOT);

    int defaults = Notification.FLAG_AUTO_CANCEL;
    if (CommonPrefs.getSoundNotify(context)) {
        defaults |= Notification.DEFAULT_SOUND;
    }
    if (CommonPrefs.getVibrateNotify(context)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    Notification notification = new NotificationCompat.Builder(context).setContentIntent(pi)
            .setSmallIcon(R.drawable.notify)
            //.setTicker(body)
            //.setWhen(time)
            .setAutoCancel(true).setDefaults(defaults).setContentTitle(title).setContentText(body).build();

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, notification);
}

From source file:com.mowares.massagerexpressclient.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  ww  w . j  a  v  a  2  s. c  om*/

private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //notification.setLatestEventInfo(context, title, message, intent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:org.thoughtcrime.securesms.service.MessageNotifier.java

private static void sendNotification(Context context, NotificationManager manager, PendingIntent launchIntent,
        Bitmap contactPhoto, String ticker, String title, String subtitle, boolean signal) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    if (!sp.getBoolean(ApplicationPreferencesActivity.NOTIFICATION_PREF, true))
        return;/*from  ww  w . j  a v a2s .  c o  m*/

    String ringtone = sp.getString(ApplicationPreferencesActivity.RINGTONE_PREF, null);
    boolean vibrate = sp.getBoolean(ApplicationPreferencesActivity.VIBRATE_PREF, true);
    String ledColor = sp.getString(ApplicationPreferencesActivity.LED_COLOR_PREF, "green");
    String ledBlinkPattern = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF, "500,2000");
    String ledBlinkPatternCustom = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM,
            "500,2000");
    String[] blinkPatternArray = parseBlinkPattern(ledBlinkPattern, ledBlinkPatternCustom);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.icon_notification);
    builder.setLargeIcon(contactPhoto);
    builder.setTicker(ticker);
    builder.setContentTitle(title);
    builder.setContentText(subtitle);
    builder.setContentIntent(launchIntent);
    builder.setSound(TextUtils.isEmpty(ringtone) || !signal ? null : Uri.parse(ringtone));

    if (signal && vibrate)
        builder.setDefaults(Notification.DEFAULT_VIBRATE);

    builder.setLights(Color.parseColor(ledColor), Integer.parseInt(blinkPatternArray[0]),
            Integer.parseInt(blinkPatternArray[1]));

    manager.notify(NOTIFICATION_ID, builder.build());
}

From source file:com.alex.vmandroid.services.RecordDBService.java

@Override
public void onCreate() {
    super.onCreate();

    //region ????
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Intent intent = new Intent(this, RecordDBActivity.class);
    //PendingIntent 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    mBuilder.setSmallIcon(R.drawable.vm_android_app_icon).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.record)).setContentIntent(pendingIntent);
    Notification mNotification = mBuilder.build();

    //  ?  //from ww  w  .  j  a va 2  s  . c  o m
    //mNotification.icon = R.drawable.icon_upload_location;
    //??
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT ??  FLAG_AUTO_CANCEL  ??
    //???Light
    mNotification.defaults = Notification.DEFAULT_VIBRATE;
    //??
    mNotification.tickerText = "???";
    //?
    mNotification.when = System.currentTimeMillis();

    //  ?  
    //mNotification.icon = R.drawable.icon_upload_location;
    //??
    mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT ??  FLAG_AUTO_CANCEL  ??
    //???Light
    mNotification.defaults = Notification.DEFAULT_VIBRATE;
    //??
    mNotification.tickerText = "???";
    //?
    mNotification.when = System.currentTimeMillis();
    //id??
    int notifyId = 1001;
    startForeground(notifyId, mNotification);
    //endregion

    //region ?
    mReceiver = new RecordDBReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(RecordDBService.RecordDBServiceAction);
    registerReceiver(mReceiver, intentFilter);
    mReceiver2 = new MessageReceiver();
    intentFilter = new IntentFilter();
    intentFilter.addAction(RecordDBReceiver.ACTION);
    registerReceiver(mReceiver2, intentFilter);
    //endregion

    //region ??
    mLocationClient = new AMapLocationClient(this);
    //???
    AMapLocationClientOption locationOption = new AMapLocationClientOption();
    //??
    mLocationClient.setLocationListener(this);
    //???Battery_Saving?Device_Sensors?
    locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
    //?,??,2000ms
    locationOption.setInterval(2000);
    //??
    mLocationClient.setLocationOption(locationOption);
    //endregion
}

From source file:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java

private static void fireNotification(Context c, int notificationId, PendingIntent contentIntent, String title,
        String text, List<String> rows, String summary, String ticker, int smallIcon, int largeIcon,
        List<Action> actions, boolean keepNotification) {
    int defaults = Notification.DEFAULT_LIGHTS;
    if (Preferences.getBoolean(c, Preferences.NOTIFICATION_VIBRATE, true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }/*from   w w  w.j  ava 2s  .c o m*/

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(title)
            .setSmallIcon(smallIcon).setLargeIcon(BitmapFactory.decodeResource(c.getResources(), largeIcon))
            .setTicker(ticker).setContentText(text).setLocalOnly(true).setContentIntent(contentIntent)
            .setWhen(System.currentTimeMillis()).setAutoCancel(!keepNotification).setDefaults(defaults);

    String soundUri = Preferences.getString(c, Preferences.NOTIFICATION_RINGTONE, null);
    if (!TextUtils.isEmpty(soundUri)) {
        builder.setSound(Uri.parse(soundUri));
    }

    if (actions != null) {
        for (Action action : actions) {
            builder.addAction(action.drawable, c.getString(action.text), action.intent);
        }
    }

    Notification notification;
    if (rows == null) {
        notification = builder.build();
    } else {
        NotificationCompat.InboxStyle styled = new NotificationCompat.InboxStyle(builder);
        for (String row : rows) {
            styled.addLine(row);
        }
        styled.setSummaryText(summary);
        notification = styled.build();
    }

    NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm == null) {
        DebugLog.e("Cannot obtain notification manager");
        return;
    }

    nm.notify(notificationId, notification);
}

From source file:realizer.com.schoolgenieparent.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///from ww  w .  jav  a  2 s  .  c  o  m
private static void generateNotification(Context context, String message) {
    DatabaseQueries qr = new DatabaseQueries(context);
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
    String date = df.format(calendar.getTime());
    int icon = R.mipmap.ic_launcher;
    String[] msg = message.split("@@@");
    SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Log.d("Feature Type=", msg[0]);

    if (msg[0].equals("GroupConversation")) {
        Bundle b = new Bundle();
        String studid = sharedpreferences.getString("UidName", "");
        if (msg[6].equals(studid)) {

            NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
            Log.d("Message=", message);
            Notification notification;
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

            String title = context.getString(R.string.app_name);
            Intent notificationIntent = new Intent(context, DrawerActivity.class);
            //// notificationIntent.putExtra("FragName","Chat");
            // set intent so it does not start a new activity
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            SharedPreferences.Editor edit = sharedpreferences.edit();
            edit.putString("FragName", "Chat");
            edit.commit();

            PendingIntent intent = PendingIntent.getActivity(context, notificatinViewStarID, notificationIntent,
                    0);
            int num = ++numStarMessages;
            builder.setAutoCancel(true);
            builder.setContentTitle("Chat");
            if (num == 1) {
                builder.setContentText(msg[6]);
            } else {
                builder.setContentText("You have received " + num + " Messages.");
            }

            builder.setSmallIcon(icon);
            builder.setContentIntent(intent);
            builder.setOngoing(false); //API level 16
            builder.setNumber(num);
            builder.setDefaults(Notification.DEFAULT_SOUND);
            builder.setDefaults(Notification.DEFAULT_VIBRATE);
            builder.build();
            notification = builder.getNotification();

            notificationManager.notify(notificatinViewStarID, notification);

            DatabaseQueries qr1 = new DatabaseQueries(context);
            edit.putString("ReceiverId", msg[2]);
            edit.putString("ReceiverName", msg[3]);
            edit.putString("ReceiverUrl", msg[5]);

            b.putString("ReceiverId", msg[2]);
            b.putString("ReceiverName", msg[3]);
            b.putString("ReceiverUrl", msg[5]);
            String std = sharedpreferences.getString("SyncStd", "");
            String div = sharedpreferences.getString("SyncDiv", "");

            SimpleDateFormat df1 = new SimpleDateFormat("dd/MM/yyyy kk:mm:ss");
            String date1 = df1.format(calendar.getTime());
            Date sendDate = new Date();
            try {
                sendDate = df.parse(date1);
            } catch (ParseException e) {
                e.printStackTrace();
            }

            ArrayList<TeacherQuerySendModel> allChat = qr.GetQueuryData(msg[2]);
            boolean isPresentNot = false;
            for (int i = 0; i < allChat.size(); i++) {
                if (allChat.get(i).getText().equals(msg[4])) {
                    isPresentNot = true;
                    break;
                } else {
                    isPresentNot = false;
                }
            }
            long n = 0;
            if (!isPresentNot) {
                n = qr1.insertQuery(msg[1], msg[2], msg[3], msg[6], msg[4], msg[5], date1, "true", sendDate);
                if (n >= 0) {
                    ArrayList<TeacherQuery1model> temp = qr.GetInitiatedChat("true");

                    boolean isPresent = false;
                    for (int i = 0; i < temp.size(); i++) {
                        if (temp.get(i).getUid().equals(msg[2])) {
                            isPresent = true;
                            break;
                        }
                    }
                    int unread = qr1.GetUnreadCount(msg[2]);
                    if (isPresent) {
                        qr1.updateInitiatechat(std, div, msg[3], "true", msg[2], unread + 1, msg[5]);
                    } else {
                        long m = 0;
                        m = qr1.insertInitiatechat(msg[3], "true", msg[2], 0, msg[5]);
                        if (m > 0)
                            Log.d("Group Conversation", " Done!!!");
                        else
                            Log.d("Group Conversation", "Not Done!!!");
                    }

                    if (n > 0) {
                        NotificationModel obj = qr.GetNotificationByUserId(msg[2]);
                        if (obj.getId() == 0) {
                            n = 0;
                            NotificationModel notification1 = new NotificationModel();
                            notification1.setNotificationId(9);
                            notification1.setNotificationDate(date);
                            notification1.setNotificationtype("Message");
                            notification1.setMessage(msg[4]);
                            notification1.setIsRead("false");
                            notification1.setAdditionalData2(msg[3]);
                            notification1.setAdditionalData1(msg[5] + "@@@" + (unread + 1));
                            n = qr.InsertNotification(notification1);
                            if (Singleton.getResultReceiver() != null)
                                Singleton.getResultReceiver().send(1, null);
                        } else {
                            n = 0;
                            obj.setMessage(msg[4]);
                            obj.setNotificationDate(date);
                            obj.setAdditionalData1(msg[5] + "@@@" + (unread + 1));

                            n = qr.UpdateNotification(obj);

                            Bundle b1 = new Bundle();
                            b1.putInt("NotificationId", 1);
                            b1.putString("NotificationDate", date);
                            b1.putString("NotificationType", "Query");
                            b1.putString("NotificationMessage", msg[4]);
                            b1.putString("IsNotificationread", "false");
                            b1.putString("AdditionalData1", msg[5] + "@@@" + (unread + 1));
                            b1.putString("AdditionalData2", msg[3]);

                            if (Singleton.getResultReceiver() != null)
                                Singleton.getResultReceiver().send(1, b);
                        }
                    }
                    Log.d("Conversation", " Done!!!");
                } else {
                    Log.d("Conversation", " Not Done!!!");
                }
            }

        }

        Singleton obj = Singleton.getInstance();
        if (obj.getResultReceiver() != null) {
            obj.getResultReceiver().send(100, b);
        }
    }
}

From source file:edu.oakland.cse480.GCMIntentService.java

public void sendCustNotification(String incomingMsg) {
    Log.i("incomingMsg = ", "" + incomingMsg);
    int msgCode;//  w w w .j  ava  2  s  .  com
    try {
        msgCode = Character.getNumericValue(incomingMsg.charAt(0));
    } catch (Exception e) {
        msgCode = 0;
    }
    String msg;
    //String[] separated = incomingMsg.split("|");
    //separated[0] = separated[0]; //discard
    //separated[1] = separated[1] + ""; 
    //separated[2] = separated[2] + ""; //Additional message with "" to negate a null

    boolean showNotification = true;

    Intent intent;

    switch (msgCode) {
    case 1:
        msg = "A new player joined the game";
        intent = new Intent("UpdateGameLobby");
        intent.putExtra("GAMESTARTED", false);
        this.sendBroadcast(intent);
        break;
    case 2:
        msg = "The game has started";
        intent = new Intent("UpdateGameLobby");
        intent.putExtra("GAMESTARTED", true);
        this.sendBroadcast(intent);
        break;
    case 3:
        msg = "It is your turn to bet";
        intent = new Intent("UpdateGamePlay");
        this.sendBroadcast(intent);
        //Stuff
        break;
    case 4:
        msg = "Flop goes";
        break;
    case 5:
        msg = "A card has been dealt";
        //Stuff
        break;
    case 6:
        msg = "The river card, has been dealt";
        //Stuff
        break;
    case 7:
        msg = "Hand is over. Winner was " + incomingMsg.substring(1);
        intent = new Intent("UpdateGamePlay");
        intent.putExtra("WINNER", "Winner of last hand: " + incomingMsg.substring(1));
        this.sendBroadcast(intent);
        //Stuff
        break;
    case 8:
        msg = "Game is over. Winner was " + incomingMsg.substring(1);
        intent = new Intent("UpdateGamePlay");
        intent.putExtra("WINNER", "Winner of Game: " + incomingMsg.substring(1));
        this.sendBroadcast(intent);
        //Stuff
        break;
    default:
        msg = "Switch case isn't working";
        showNotification = false;
        //Some default stuff
        break;
    }

    if (showNotification) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent newIntent = new Intent(this, Gameplay.class);
        newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, 0);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Poker Notification")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

        mBuilder.setContentIntent(contentIntent);
        Notification notification = mBuilder.build();
        notification.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND
                | Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

        mNotificationManager.notify(NOTIFICATION_ID, notification);

    }
}

From source file:com.zion.htf.receiver.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // Get preferences
    Resources res = context.getResources();
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

    int setId, alarmId;
    try {/*from  w  w w.j ava  2  s  .  c  o m*/
        if (0 == (setId = intent.getIntExtra("set_id", 0)))
            throw new MissingArgumentException("set_id", "int");
        if (0 == (alarmId = intent.getIntExtra("alarm_id", 0)))
            throw new MissingArgumentException("alarm_id", "int");
    } catch (MissingArgumentException e) {
        throw new RuntimeException(e.getMessage());
    }

    // Fetch info about the set
    try {
        // VIBRATE will be added if user did NOT disable notification vibration
        // SOUND won't as it is set even if it is to the default value
        int flags = Notification.DEFAULT_LIGHTS;
        MusicSet set = MusicSet.getById(setId);
        Artist artist = set.getArtist();

        SimpleDateFormat dateFormat;
        if ("fr".equals(Locale.getDefault().getLanguage())) {
            dateFormat = new SimpleDateFormat("HH:mm", Locale.FRANCE);
        } else {
            dateFormat = new SimpleDateFormat("h:mm aa", Locale.ENGLISH);
        }

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, ArtistDetailsActivity.class);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);// Do not start a  new activity but reuse the existing one (if any)
        resultIntent.putExtra(ArtistDetailsActivity.EXTRA_SET_ID, setId);

        // Manipulate the TaskStack in order to get a good back button behaviour. See http://developer.android.com/guide/topics/ui/notifiers/notifications.html
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(ArtistDetailsActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Extract a bitmap from a file to use a large icon
        Bitmap largeIconBitmap = BitmapFactory.decodeResource(context.getResources(),
                artist.getPictureResourceId());

        // Builds the notification
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_notify_app_icon)
                .setLargeIcon(largeIconBitmap).setAutoCancel(true).setContentIntent(resultPendingIntent)
                .setContentTitle(artist.getName())
                .setContentText(String.format(context.getString(R.string.alarm_notification), artist.getName(),
                        set.getStage(), dateFormat.format(set.getBeginDate())));

        // Vibrate settings
        Boolean defaultVibrate = true;
        if (!pref.contains(res.getString(R.string.pref_key_notifications_alarms_vibrate))) {
            // Get the system default for the vibrate setting
            AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            if (null != audioManager) {
                switch (audioManager.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    defaultVibrate = false;
                    break;
                case AudioManager.RINGER_MODE_NORMAL:
                case AudioManager.RINGER_MODE_VIBRATE:
                default:
                    defaultVibrate = true;
                }
            }
        }
        Boolean vibrate = pref.getBoolean(res.getString(R.string.pref_key_notifications_alarms_vibrate),
                defaultVibrate);

        // Ringtone settings
        String ringtone = pref.getString(res.getString(R.string.pref_key_notifications_alarms_ringtone),
                Settings.System.DEFAULT_NOTIFICATION_URI.toString());

        // Apply notification settings
        if (!vibrate) {
            notificationBuilder.setVibrate(new long[] { 0l });
        } else {
            flags |= Notification.DEFAULT_VIBRATE;
        }

        notificationBuilder.setSound(Uri.parse(ringtone));

        // Get the stage GPS coordinates
        try {
            Stage stage = Stage.getByName(set.getStage());

            // Add the expandable notification buttons
            PendingIntent directionsButtonPendingIntent = PendingIntent
                    .getActivity(context, 1,
                            new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(String.format(Locale.ENGLISH,
                                            "http://maps.google.com/maps?f=d&daddr=%f,%f", stage.getLatitude(),
                                            stage.getLongitude()))),
                            Intent.FLAG_ACTIVITY_NEW_TASK);
            notificationBuilder.addAction(R.drawable.ic_menu_directions,
                    context.getString(R.string.action_directions), directionsButtonPendingIntent);
        } catch (InconsistentDatabaseException e) {
            // Although this is a serious error, its impact on functionality is minimal.
            // Report this through piwik
            if (BuildConfig.DEBUG)
                e.printStackTrace();
        }

        // Finalize the notification
        notificationBuilder.setDefaults(flags);
        Notification notification = notificationBuilder.build();

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(set.getStage(), 0, notification);

        SavedAlarm.delete(alarmId);
    } catch (SetNotFoundException e) {
        throw new RuntimeException(e.getMessage());
        // TODO: Notify that an alarm was planned but some error prevented to display it properly. Open AlarmManagerActivity on click
        // Report this through piwik
    }
}