Example usage for android.app PendingIntent FLAG_UPDATE_CURRENT

List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT

Introduction

In this page you can find the example usage for android.app PendingIntent FLAG_UPDATE_CURRENT.

Prototype

int FLAG_UPDATE_CURRENT

To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.

Click Source Link

Document

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

Usage

From source file:at.ac.uniklu.mobile.sportal.service.MutingService.java

/**
 * Schedules an alarm through the AlarmManager. Alarms are typically scheduled at time when courses begin or end.
 * @param time the time at which the alarm will go off
 * @param action the action that will be called when the alarm goes off
 *///from   w w  w.ja  va2  s  .co  m
private void scheduleAlarm(long time, int action, int alarmId) {
    Log.d(TAG, "scheduling alarm action " + action + " @ " + new Date(time).toLocaleString() + " (aID:"
            + alarmId + ")");

    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent alarmIntent = new Intent(this, OnAlarmReceiver.class).putExtra(ACTION, action)
            .putExtra(EXTRA_ALARM_ID, alarmId);
    PendingIntent pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    time = SystemClock.elapsedRealtime() + (time - System.currentTimeMillis()); //  convert unixtime to system runtime
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pendingAlarmIntent);
}

From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java

private void initializeDemoButton() {
    mDemoTV.setOnClickListener(new View.OnClickListener() {
        @Override//from   w ww  . j  ava  2 s  .  co m
        public void onClick(View v) {
            Bundle newExtra = new Bundle();

            NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
            String notificationText = "Sample notification subject";
            String notificationBigText = "Sample notification body. This is where the details of the notification will be shown.";

            StringBuilder sb = new StringBuilder();
            sb.append("[").append("example").append("] ");
            sb.append(notificationText);
            if (notificationBigText.length() > 0) {
                sb.append(" -- ").append(notificationBigText);
            }

            RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.custom_notification);
            contentView.setTextViewText(R.id.customNotificationText,
                    getString(R.string.placeholder_notification_text));
            builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString()).setExtras(newExtra)
                    .setContentTitle("Sample Notification Title").setContent(contentView);

            // Creates an explicit intent for the SettingsActivity in the app
            Intent settingsIntent = new Intent(mContext, SettingsActivity.class);

            // The stack builder object will contain an artificial back stack for the
            // started Activity.
            // This ensures that navigating backward from the Activity leads out of
            // the application to the Home screen.
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
            // Adds the back stack for the Intent (but not the Intent itself)
            stackBuilder.addParentStack(SettingsActivity.class);
            // Adds the Intent that starts the Activity to the top of the stack
            stackBuilder.addNextIntent(settingsIntent);
            PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(settingsPendingIntent).setAutoCancel(true);

            ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                    .notify(Constants.NOTIFICATION_ID, builder.build());

            Toast.makeText(mContext, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show();

            if (mDismissPlaceholderNotif) {
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                                .cancel(Constants.NOTIFICATION_ID);
                    }
                }, mPlaceholderNotifDismissDelayMillis);
            }
        }
    });
}

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

@Override
public void onReceive(Context context, Intent intent) {
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    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_sms", true);

    if (notify == false)
        return;//  w  w  w .  j  a  va  2 s  .  co m

    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;
    String str = "";
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];
        for (int i = 0; i < msgs.length; i++) {
            msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            str += msgs[i].getMessageBody().toString();
            str += "\n";
        }

        NotificationCompat.Builder mBuilder;

        if (main != null) {
            main.addNewMessage(str);
            return;
        }

        boolean use_profile_picture = false;
        Bitmap profile_picture = null;

        String origin_name = null;
        try {
            origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress());
            if (origin_name == null)
                origin_name = msgs[0].getDisplayOriginatingAddress();
        } catch (Exception e) {
        }
        if (origin_name == null)
            origin_name = "Unknown";
        try {
            profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap(
                    fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300);
            use_profile_picture = true;
        } catch (Exception e) {
            use_profile_picture = false;
        }

        Resources res = context.getResources();
        int positionOfBase64End = str.lastIndexOf("=");
        if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) {
            mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon)
                    .setContentTitle(origin_name).setColor(0xFFB71C1C)
                    .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).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 (str.toString().charAt(0) == '%'
                && (str.toString().length() == 10 || str.toString().length() == 9)) {
            int lastIndex = str.toString().lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C)
                        .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                        .setSmallIcon(R.drawable.raven_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 (str.toString().charAt(0) == '%' && str.toString().length() >= 120
                && str.toString().length() < 125) { // DH Handshake
            int lastIndex = str.toString().lastIndexOf("=");
            if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C)
                        .setContentText(res.getString(R.string.sms_receiver_handshake_received))
                        .setSmallIcon(R.drawable.raven_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 { // unencrypted messages
            if (all) {
                mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name)
                        .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(str))
                        .setSmallIcon(R.drawable.raven_notification_icon);
                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.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress());

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MainActivity.class);
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, 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 (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop)
            mNotificationManager.notify(7, mBuilder.build());

        // Save SMS if default app
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
                && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) {
            ContentValues values = new ContentValues();
            values.put("address", msgs[0].getDisplayOriginatingAddress());
            values.put("body", str.replace("\n", "").replace("\r", ""));

            if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
                context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values);

        }
    }

}

From source file:net.networksaremadeofstring.rhybudd.ZenossPoller.java

private void PollerCheck() {
    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    Intent Poller = new Intent(this, ZenossPoller.class);

    if (settings.getBoolean("AllowBackgroundService", true)) {
        //Log.i("PollerCheck","Background scanning enabled!");
        Notifications.SendStickyNotification(this);

        Poller.putExtra("events", true);
        PendingIntent Monitoring = PendingIntent.getService(this, 0, Poller, PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.FLAG_UPDATE_CURRENT
        am.cancel(Monitoring);/*w w w  .ja v a  2s.c  o m*/
        try {
            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, (long) 0,
                    Long.parseLong(settings.getString("BackgroundServiceDelay", "60")) * 1000, Monitoring);
        } catch (Exception e) {
            am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, (long) 0, 60000, Monitoring);
            BugSenseHandler.sendExceptionMessage("ZenossPoller", "PollerCheck", e);
        }
    } else {
        //Log.i("PollerCheck","Background scanning disabled!");
        Poller.putExtra("events", true);
        PendingIntent Monitoring = PendingIntent.getService(this, 0, Poller, PendingIntent.FLAG_UPDATE_CURRENT);//PendingIntent.FLAG_UPDATE_CURRENT
        am.cancel(Monitoring);
        mNM.cancel(Notifications.NOTIFICATION_POLLED_STICKY);
    }

    /*if(settings.getBoolean("refreshCache", true))
    {
       //Log.i("PollerCheck","Background cache refresh enabled!");
               
       Poller.putExtra("refreshCache", true);
       PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller, PendingIntent.FLAG_UPDATE_CURRENT);
       am.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, 10000, AlarmManager.INTERVAL_HOUR, CacheRefresh);
    }
    else
    {
       //Log.i("PollerCheck","Background cache refresh disabled!");
       Poller.putExtra("refreshCache", true);
       PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller, PendingIntent.FLAG_UPDATE_CURRENT);
       am.cancel(CacheRefresh);
    }*/

    //We use a SyncAdapter now like good citizens
    try {
        if (settings.getBoolean("refreshCache", true)) {
            Poller.putExtra("refreshCache", true);
            PendingIntent CacheRefresh = PendingIntent.getService(this, 1, Poller,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            am.cancel(CacheRefresh);
            SharedPreferences.Editor editor = settings.edit();
            editor.putBoolean("refreshCache", false);
            editor.commit();
        }
    } catch (Exception e) {
        e.printStackTrace();
        BugSenseHandler.sendExceptionMessage("ZenossPoller", "cancel refresh cache poller", e);
    }
}

From source file:com.userhook.UserHook.java

public static Notification handlePushMessage(Map<String, String> data) {

    String message = data.get("message");
    String title = "";

    if (data.containsKey("title") && data.get("title") != null) {
        title = data.get("title");
    } else {/*from  ww  w.jav  a2 s .c  om*/
        title = applicationContext.getApplicationInfo().loadLabel(applicationContext.getPackageManager())
                .toString();
    }

    Map<String, Object> payload = new HashMap<>();
    if (data.containsKey("payload")) {
        try {
            JSONObject json = new JSONObject(data.get("payload"));
            payload = UHJsonUtils.toMap(json);

            // check if this is a feedback reply
            if (json.has("new_feedback") && json.getBoolean("new_feedback")) {
                UserHook.setHasNewFeedback(true);
            } else {
                UserHook.setHasNewFeedback(false);
            }

        } catch (JSONException e) {
            Log.e("uh", "error parsing push notification payload");
        }
    }

    // message received
    Intent intent;

    if (pushMessageListener != null) {
        intent = pushMessageListener.onPushMessage(payload);
    } else {
        // default to opening the main activity
        intent = applicationContext.getPackageManager()
                .getLaunchIntentForPackage(applicationContext.getPackageName());
    }

    // convert data to a try Map<String,String> since it will come in as an ArrayMap
    if (data instanceof ArrayMap) {
        HashMap<String, String> hashMap = new HashMap<>();
        for (String key : data.keySet()) {
            hashMap.put(key, data.get(key));
        }
        data = hashMap;
    }

    intent.putExtra(UserHook.UH_PUSH_DATA, (Serializable) data);
    intent.putExtra(UserHook.UH_PUSH_TRACKED, false);
    if (payload.size() > 0) {
        intent.putExtra(UserHook.UH_PUSH_PAYLOAD, data.get("payload"));
    }

    //PendingIntent.FLAG_UPDATE_CURRENT is required to pass along our Intent Extras
    PendingIntent pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    try {
        ApplicationInfo appInfo = applicationContext.getPackageManager()
                .getApplicationInfo(applicationContext.getPackageName(), PackageManager.GET_META_DATA);

        int pushIcon = appInfo.icon;
        // check for a custom push icon
        if (pushNotificationIcon > 0) {
            pushIcon = pushNotificationIcon;
        }

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext)
                .setSmallIcon(pushIcon).setContentText(message).setContentTitle(title).setAutoCancel(true)
                .setContentIntent(pendingIntent);

        // use default sound
        notificationBuilder.setDefaults(Notification.DEFAULT_SOUND);

        return notificationBuilder.build();

    } catch (Exception e) {
        Log.e("uh", "error create push notification", e);
        return null;
    }

}

From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java

protected PendingIntent getCallback() {
    // TODO: Maybe do a callback per probe, so they can be cancelled individually
    return PendingIntent.getService(this, 0, new Intent(this, getClass()), PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +/*from   w  w  w  . ja va2  s  . c  om*/
 * @throws JSONException 
 */
@SuppressLint("InlinedApi")
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setTicker(json.getString("title"))
            .setContentTitle(json.getString("message")).setContentIntent(contentIntent);

    String message = json.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());
}

From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java

@Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "Received start id " + startId + ": " + intent);
        if (intent != null) {
            try {
                params = new JSONObject(intent.getStringExtra("params"));
                headers = new JSONObject(intent.getStringExtra("headers"));
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();/*from w w w . j a  v a2  s .co m*/
            }
            url = intent.getStringExtra("url");
            stationaryRadius = Float.parseFloat(intent.getStringExtra("stationaryRadius"));
            distanceFilter = Integer.parseInt(intent.getStringExtra("distanceFilter"));
            scaledDistanceFilter = distanceFilter;
            desiredAccuracy = Integer.parseInt(intent.getStringExtra("desiredAccuracy"));
            locationTimeout = Integer.parseInt(intent.getStringExtra("locationTimeout"));
            isDebugging = Boolean.parseBoolean(intent.getStringExtra("isDebugging"));
            notificationTitle = intent.getStringExtra("notificationTitle");
            notificationText = intent.getStringExtra("notificationText");

            // Build a Notification required for running service in foreground.
            Intent main = new Intent(this, BackgroundGpsPlugin.class);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, main,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Notification.Builder builder = new Notification.Builder(this);
            builder.setContentTitle(notificationTitle);
            builder.setContentText(notificationText);
            builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
            builder.setContentIntent(pendingIntent);
            Notification notification;
            if (android.os.Build.VERSION.SDK_INT >= 16) {
                notification = buildForegroundNotification(builder);
            } else {
                notification = buildForegroundNotificationCompat(builder);
            }
            notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
                    | Notification.FLAG_NO_CLEAR;
            startForeground(startId, notification);
        }
        Log.i(TAG, "- url: " + url);
        Log.i(TAG, "- params: " + params.toString());
        Log.i(TAG, "- headers: " + headers.toString());
        Log.i(TAG, "- stationaryRadius: " + stationaryRadius);
        Log.i(TAG, "- distanceFilter: " + distanceFilter);
        Log.i(TAG, "- desiredAccuracy: " + desiredAccuracy);
        Log.i(TAG, "- locationTimeout: " + locationTimeout);
        Log.i(TAG, "- isDebugging: " + isDebugging);
        Log.i(TAG, "- notificationTitle: " + notificationTitle);
        Log.i(TAG, "- notificationText: " + notificationText);

        this.setPace(false);

        //We want this service to continue running until it is explicitly stopped
        return START_REDELIVER_INTENT;
    }

From source file:com.perm.DoomPlay.PlayingService.java

private Notification createNotification() {

    Intent intentActivity;/*from   w  w w  .ja v  a  2 s .  com*/

    if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) {
        intentActivity = new Intent(FullPlaybackActivity.actionReturnFull);
        intentActivity.setClass(this, FullPlaybackActivity.class);
        intentActivity.putExtra(FileSystemActivity.keyMusic, audios);
    } else {
        intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios);
    }
    intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Notification notification = new Notification();
    notification.contentView = getNotifViews(R.layout.notif);
    notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
    notification.contentIntent = PendingIntent.getActivity(this, 0, intentActivity,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.icon = isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play;

    return notification;
}

From source file:com.abhijitvalluri.android.fitnotifications.setup.AppIntroActivity.java

private void addDemoSlide() {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean dismissPlaceholderNotif = preferences
            .getBoolean(getString(R.string.dismiss_placeholder_notif_key), false);
    final int placeholderNotifDismissDelayMillis = preferences
            .getInt(getString(R.string.placeholder_dismiss_delay_key), Constants.DEFAULT_DELAY_SECONDS) * 1000;
    final Handler handler = new Handler();

    // Demo/*from w  ww  . j  av  a 2s .c o  m*/
    addSlide(new SimpleSlide.Builder().layout(R.layout.fragment_intro).title(R.string.intro_done_title)
            .description(R.string.intro_done_desc).image(R.drawable.intro_done).background(R.color.colorAccent)
            .backgroundDark(R.color.colorAccentDark).buttonCtaLabel(R.string.test_notification)
            .buttonCtaClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle newExtra = new Bundle();

                    NotificationCompat.Builder builder = new NotificationCompat.Builder(AppIntroActivity.this);
                    String notificationText = "Sample notification subject";
                    String notificationBigText = "Sample notification body. This is where the details of the notification will be shown.";

                    StringBuilder sb = new StringBuilder();
                    sb.append("[").append("example").append("] ");
                    sb.append(notificationText);
                    if (notificationBigText.length() > 0) {
                        sb.append(" -- ").append(notificationBigText);
                    }

                    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
                    contentView.setTextViewText(R.id.customNotificationText,
                            getString(R.string.placeholder_notification_text));
                    builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString())
                            .setExtras(newExtra).setContentTitle("Sample Notification Title")
                            .setContent(contentView);

                    // Creates an explicit intent for the SettingsActivity in the app
                    Intent settingsIntent = new Intent(AppIntroActivity.this, SettingsActivity.class);

                    // The stack builder object will contain an artificial back stack for the
                    // started Activity.
                    // This ensures that navigating backward from the Activity leads out of
                    // the application to the Home screen.
                    TaskStackBuilder stackBuilder = TaskStackBuilder.create(AppIntroActivity.this);
                    // Adds the back stack for the Intent (but not the Intent itself)
                    stackBuilder.addParentStack(SettingsActivity.class);
                    // Adds the Intent that starts the Activity to the top of the stack
                    stackBuilder.addNextIntent(settingsIntent);
                    PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    builder.setContentIntent(settingsPendingIntent).setAutoCancel(true);

                    ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,
                            builder.build());

                    Toast.makeText(AppIntroActivity.this, getString(R.string.test_notification_sent),
                            Toast.LENGTH_LONG).show();

                    if (dismissPlaceholderNotif) {
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                                        .cancel(NOTIFICATION_ID);
                            }
                        }, placeholderNotifDismissDelayMillis);
                    }
                }
            }).build());
}