Example usage for android.app PendingIntent FLAG_ONE_SHOT

List of usage examples for android.app PendingIntent FLAG_ONE_SHOT

Introduction

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

Prototype

int FLAG_ONE_SHOT

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

Click Source Link

Document

Flag indicating that this PendingIntent can be used only once.

Usage

From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java

public void notifyAnnouncement(String announcement, String URL) {
    Uri webpage = Uri.parse(URL);
    Intent contentIntent = new Intent(Intent.ACTION_VIEW, webpage);
    PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, contentIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Intent settingsIntent = new Intent(this, SettingsActivity.class);
    settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS);
    settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 1 /* Request code */, settingsIntent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle();
    notifStyle.bigText(announcement);//from   w  ww. ja  va2  s . com
    notifStyle.setBigContentTitle(getString(R.string.notif_announcement_title));

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_icon_nodpi)
            .setContentTitle(getString(R.string.notif_announcement_title)).setContentText(announcement)
            .setAutoCancel(true).setSound(defaultSoundUri)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent)
            .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off,
                    getString(R.string.notif_action_options), settingsPendingIntent);

    // Get an instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and issues it with notification manager.
    notificationManager.notify(NOTIFICATION_ID_ANNOUNCEMENT, notificationBuilder.build());
}

From source file:com.teachmate.teachmate.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.notif_icon_big);

    if (intType == 2) {
        Intent question = new Intent(this, MainActivity.class);
        question.putExtra("type", "Replies");
        question.putExtra("askedby", askedby);
        question.putExtra("userid_questions", userid_questions);
        question.putExtra("questionmessage", questionmessage);
        question.putExtra("asked_time_questions", asked_time_questions);
        question.putExtra("imagepath", imagepath);
        question.putExtra("Category", category);
        question.putExtra("questionid", questionid);
        question.putExtra("userprofession_questions", userprofession_questions);

        PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(questionid), question,
                PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notif_icon).setLargeIcon(bitmap).setContentTitle("New Answer")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(repliedby + " says " + replymessage))
                .setContentText(repliedby + " says " + replymessage).setAutoCancel(true);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } else if (intType == 3) {
        Intent requestIntent = new Intent(this, MainActivity.class);
        requestIntent.putExtra("type", "request");
        requestIntent.putExtra("NotificationRequestId", requestId);

        PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(requestId),
                requestIntent, PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notif_icon).setLargeIcon(bitmap).setContentTitle("New Request")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message))
                .setContentText(username + " : " + message).setAutoCancel(true);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } else if (intType == 4) {
        Intent responseIntent = new Intent(this, MainActivity.class);
        responseIntent.putExtra("type", "response");
        responseIntent.putExtra("NotificationResponseId", responseId);
        responseIntent.putExtra("NotificationRequestId", requestId);
        responseIntent.putExtra("NotificationResponseUserId", userId);
        responseIntent.putExtra("NotificationResponseUserName", username);
        responseIntent.putExtra("NotificationResponseMessage", message);
        responseIntent.putExtra("NotificationResponseUserProfession", responseUserProfession);
        responseIntent.putExtra("NotificationResponseUserProfilePhotoServerPath", responseUserProfilePath);

        PendingIntent contentIntent = PendingIntent.getActivity(this, Integer.parseInt(responseId),
                responseIntent, PendingIntent.FLAG_ONE_SHOT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.notif_icon).setContentTitle("New Response").setLargeIcon(bitmap)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(username + " : " + message))
                .setContentText(username + " : " + message).setAutoCancel(true);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } else if (intType == 5) {
        Intent chatIntent = new Intent(getApplicationContext(), ChatActivity.class);
        chatIntent.putExtra("ChatId", chatChatId);
        chatIntent.putExtra("Message", chatMessage);
        chatIntent.putExtra("SentOn", chatMessageTime);
        chatIntent.putExtra("SenderId", chatSenderId);
        chatIntent.putExtra("UserName", chatSenderName);
        chatIntent.putExtra("received", true);
        ChatIdMap chatIdMap = new ChatIdMap();
        chatIdMap.chatId = chatChatId;//w w w  . j  a v a  2 s .c o m
        chatIdMap.userId = chatSenderId;
        chatIdMap.userName = chatSenderName;
        ChatIdMapDBHandler.InsertChatIdMap(getApplicationContext(), chatIdMap);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),
                Integer.parseInt(chatChatId), chatIntent, PendingIntent.FLAG_ONE_SHOT);

        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String time = dateFormat.format(date);
        time = time.substring(11, time.lastIndexOf(':'));
        ChatInfo newMessage = new ChatInfo();
        newMessage.setMessage(chatMessage);
        newMessage.setSentBy(false);
        newMessage.setTimeStamp(time);
        newMessage.setChatId(chatChatId);

        ChatInfoDBHandler.InsertChatInfo(getApplicationContext(), newMessage);

        if (TempDataClass.alreadyAdded == true) {
            TempDataClass.alreadyAdded = false;
            return;
        }

        Notification mBuilder = new NotificationCompat.Builder(getApplicationContext())
                .setSmallIcon(R.drawable.notif_icon).setLargeIcon(bitmap).setContentTitle("Chat Notification")
                .setContentIntent(pendingIntent)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(chatSenderName + ":" + chatMessage))
                .setContentText(chatSenderName + ":" + chatMessage).setAutoCancel(true).build();

        mNotificationManager = (NotificationManager) getApplicationContext()
                .getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder);
    } else {

    }
}

From source file:cx.ring.model.Conference.java

public void showCallNotification(Context ctx) {
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx);
    notificationManager.cancel(notificationId);

    if (getParticipants().isEmpty())
        return;/*w  ww.  ja  v a2s  . com*/
    SipCall call = getParticipants().get(0);
    CallContact contact = call.getContact();
    final Uri call_uri = Uri.withAppendedPath(SipCall.CONTENT_URI, call.getCallId());
    PendingIntent goto_intent = PendingIntent.getActivity(ctx, new Random().nextInt(), getViewIntent(ctx),
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder noti = new NotificationCompat.Builder(ctx);
    if (isOnGoing()) {
        noti.setContentTitle(ctx.getString(R.string.notif_current_call_title, contact.getDisplayName()))
                .setContentText(ctx.getText(R.string.notif_current_call)).setContentIntent(goto_intent)
                .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup),
                        PendingIntent.getService(
                                ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END)
                                        .setClass(ctx, LocalService.class).setData(call_uri),
                                PendingIntent.FLAG_ONE_SHOT));
    } else if (isRinging()) {
        if (isIncoming()) {
            noti.setContentTitle(ctx.getString(R.string.notif_incoming_call_title, contact.getDisplayName()))
                    .setPriority(NotificationCompat.PRIORITY_MAX)
                    .setContentText(ctx.getText(R.string.notif_incoming_call)).setContentIntent(goto_intent)
                    .setFullScreenIntent(goto_intent, true)
                    .addAction(R.drawable.ic_action_accept, ctx.getText(R.string.action_call_accept),
                            PendingIntent.getService(ctx, new Random().nextInt(),
                                    new Intent(LocalService.ACTION_CALL_ACCEPT)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT))
                    .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_decline),
                            PendingIntent.getService(ctx, new Random().nextInt(),
                                    new Intent(LocalService.ACTION_CALL_REFUSE)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT));
        } else {
            noti.setContentTitle(ctx.getString(R.string.notif_outgoing_call_title, contact.getDisplayName()))
                    .setContentText(ctx.getText(R.string.notif_outgoing_call)).setContentIntent(goto_intent)
                    .addAction(R.drawable.ic_call_end_white_24dp, ctx.getText(R.string.action_call_hangup),
                            PendingIntent.getService(
                                    ctx, new Random().nextInt(), new Intent(LocalService.ACTION_CALL_END)
                                            .setClass(ctx, LocalService.class).setData(call_uri),
                                    PendingIntent.FLAG_ONE_SHOT));
        }

    } else {
        notificationManager.cancel(notificationId);
        return;
    }

    noti.setOngoing(true).setCategory(NotificationCompat.CATEGORY_CALL).setSmallIcon(R.drawable.ic_launcher);

    if (contact.getPhoto() != null) {
        Resources res = ctx.getResources();
        int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
        int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
        noti.setLargeIcon(Bitmap.createScaledBitmap(contact.getPhoto(), width, height, false));
    }
    notificationManager.notify(notificationId, noti.build());
}

From source file:com.velli.passwordmanager.ApplicationBase.java

public static void showLogoutNotification() {
    final Intent logout = new Intent(getAppContext(), IntentServiceLogOut.class);

    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getAppContext())
            .setSmallIcon(R.drawable.ic_action_fingerprint)
            .setContentTitle(getAppContext().getString(R.string.notification_log_out_title))
            .setContentText(getAppContext().getString(R.string.notification_log_out_content))
            .setColor(getAppContext().getResources().getColor(R.color.color_primary_500)).setShowWhen(false)
            .setContentIntent(/* w w  w.j  ava  2s .c  om*/
                    PendingIntent.getService(getAppContext(), -1, logout, PendingIntent.FLAG_ONE_SHOT));

    NotificationManager notificationManager = (NotificationManager) getAppContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, mBuilder.build());

}

From source file:com.preguardia.app.notification.MyGcmListenerService.java

private void showPatientNotification(String title, String message, String consultationId) {
    // Prepare intent which is triggered if the notification is selected
    Intent intent = new Intent(this, ConsultationDetailsActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_REQUEST_CODE, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_logo).setContentTitle(title).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.online.fullsail.SaveWebMedia.java

@Override
protected void onPostExecute(File download) {
    String fileString = download.toString();
    mNM.cancel(timestamp);// w w  w.  j a  v  a 2  s  . c  o m
    System.gc();
    String fileName = fileString.substring(fileString.lastIndexOf('/') + 1, fileString.length());
    String fileExt = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
    File downFile = new File(externalData, fileName);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(downFile), "application/" + fileExt);
    List<ResolveInfo> intents = this.context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (intents == null || intents.size() == 0) {
        intent.setDataAndType(Uri.fromFile(downFile), "video/" + fileExt);
        intents = this.context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        if (intents == null || intents.size() == 0) {
            intent.setDataAndType(Uri.fromFile(downFile), "image/" + fileExt);
            intents = this.context.getPackageManager().queryIntentActivities(intent,
                    PackageManager.MATCH_DEFAULT_ONLY);
            if (intents == null || intents.size() == 0) {
                intent = new Intent(Intent.ACTION_SEARCH);
                if (Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.ECLAIR) {
                    intent.setPackage("com.android.vending");
                }
                intent.putExtra("query", fileExt);

            }
        }
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(this.context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Notification notification = null;
    Resources resources = this.context.getResources();
    String[] mediaTypes = resources.getStringArray(R.array.media);
    boolean acceptedType = false;
    for (int i = 0; i < mediaTypes.length; i++) {
        if (fileExt.toLowerCase().equals(mediaTypes[i])) {
            acceptedType = true;
        }
    }
    if (acceptedType) {
        Bitmap preview = null;
        String[] videoTypes = resources.getStringArray(R.array.movFiles);
        for (int i = 0; i < videoTypes.length; i++) {
            if (fileExt.toLowerCase().equals(videoTypes[i])) {
                preview = getVideoFrame(fileString);
            }
        }
        String[] imageTypes = resources.getStringArray(R.array.movFiles);
        for (int i = 0; i < imageTypes.length; i++) {
            if (fileExt.toLowerCase().equals(imageTypes[i])) {
                preview = decodeBitmapFile(fileString);
            }
        }
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
        builder.setTicker(this.context.getString(R.string.notify_download_complete))
                .setWhen(System.currentTimeMillis())
                .setContentTitle(this.context.getString(R.string.Document_complete))
                .setContentText(this.context.getString(R.string.Pdf_completed, fileName))
                .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH)
                .setContentIntent(contentIntent);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            notification = new NotificationCompat.BigPictureStyle(builder).bigPicture(preview).build();
        } else {
            notification = builder.build();
        }
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this.context);
        builder.setContentTitle(this.context.getString(R.string.Document_complete))
                .setContentText(this.context.getString(R.string.Pdf_completed, fileName))
                .setSmallIcon(R.drawable.icon).setAutoCancel(true).setPriority(Notification.PRIORITY_HIGH)
                .setContentIntent(contentIntent);
        notification = builder.build();
    }
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    mNM.notify(timestamp, notification);
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@SuppressWarnings("deprecation")
public Notification createNotification(Bundle settings, JSONObject obj) {

    // notifications[i] = api.normalizeAPI({
    // 'string': {
    // mandatory: ['title', 'body'],
    // defaults: {'icon':'icon'}
    // },/*from   w  w w  .ja v  a 2s .com*/
    //
    // 'number': {
    // mandatory: ['id', 'timeMillisSince1970'],
    // // the number of ms after which we start prioritising more recent
    // things above you.
    // defaults: {'epsilon': 1000 * 60 * 24 * 365}
    // },
    //
    // 'boolean': {
    // defaults: {
    // 'vibrate': false,
    // 'sound': false
    // }
    // }

    int icon = settings.getInt("notification_icon", -1);
    if (icon == -1) {
        Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    Notification n = new Notification();
    n.icon = icon;
    n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    long alarmTime = obj.optLong("timeMillisSince1970");
    long displayTime = obj.optLong("displayTimestamp", alarmTime);
    n.when = displayTime;
    n.tickerText = obj.optString("body");
    n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null);

    if (obj.optBoolean("vibrate")) {
        n.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (obj.optBoolean("sound")) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    String uriString = settings.getString("content_uri_prefix");
    if (uriString == null) {
        Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    if (uriString.contains("%d")) {
        uriString = String.format(uriString, obj.optInt("id"));
    }
    Uri uri = Uri.parse(uriString);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(uri);
    n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT);
    return n;
}

From source file:com.nutsuser.ridersdomain.activities.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// www.  j  a va  2s . c  o  m
 */
/* private void sendNotification(String message, long number_push) {
Log.e("message: ", "" + message);
 *//*    try {
       *//**//* mJsonObject = new JSONObject(message);
              // mStringType = mJson_Object.getString("type");
              mStringUsername = mJson_Object.getString("username");
              senderUserId = mJson_Object.getInt("sender_user_id");
              mStringMessage = mJson_Object.getString("message");
              Log.e("mStringMessage: ", "" + mStringMessage);*//**//*
                                                                            
                                                                    } catch (JSONException e) {
                                                                    Log.e("JSON Parser", "Error parsing data " + e.toString());
                                                                    }*//*
                                                                        // Intent intent = new Intent(this, MessagesActivity.class);
                                                                        //intent.putExtra("message_username", mStringUsername);
                                                                        //intent.putExtra("whrlocation", "notification");
                                                                                
                                                                        //intent.putExtra("userId2", senderUserId);
                                                                        // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                                                        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, PendingIntent.FLAG_ONE_SHOT);
                                                                                
                                                                        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                                                                                
                                                                        //Bitmap bitmap =  BitmapFactory.decodeResource(this.getResources(),
                                                                        // R.drawable.ic_launcher);
                                                                        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                                                                             .setSmallIcon(R.drawable.ic_launcher)
                                                                             .setContentTitle("Rider Opinion")
                                                                             .setContentText(message)
                                                                             .setAutoCancel(true)
                                                                             .setSound(defaultSoundUri)
                                                                             .setContentIntent(pendingIntent);
                                                                        notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
                                                                        NotificationManager notificationManager =
                                                                             (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                                                                                
                                                                        notificationManager.notify((int) number_push *//**//* ID of notification *//**//*, notificationBuilder.build());
                                                                                                                                                        }*/
//This method is generating a notification and displaying the notification
private void sendNotification(String message) {
    Intent intent = new Intent(this, NotificationListActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = 0;
    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.app_icon).setContentTitle("Rider Opinion").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

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

From source file:com.lloydtorres.stately.push.TrixHelper.java

/**
 * Builds the notification for issue notices. Unlike other types of notifications, issue
 * notices are limited to one notification. This prevents the status bar from
 * being spammed if the user has more than one nation.
 * @param c App context//w  ww .  j  ava  2s .  c  o m
 * @param account Nation name of notice's source
 * @param notice Target issue notice
 */
public static void processIssueNotice(Context c, String account, Notice notice) {
    // Check if the user wants to see notifications for issues
    if (!SettingsActivity.getIssuesNotificationSetting(c)) {
        return;
    }

    Bundle issueBundle = new Bundle();
    issueBundle.putInt(LoginActivity.ROUTE_PATH_KEY, LoginActivity.ROUTE_ISSUES);
    issueBundle.putInt(StatelyActivity.NAV_INIT, StatelyActivity.ISSUES_FRAGMENT);

    NotificationCompat.Builder builder = getBaseBuilder(c, account)
            .setContentTitle(c.getString(R.string.notifs_new_issue)).setOnlyAlertOnce(true)
            .setContentIntent(PendingIntent.getActivity(c, 0, getLoginActivityIntent(c, account, issueBundle),
                    PendingIntent.FLAG_ONE_SHOT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setSmallIcon(R.drawable.ic_menu_issues);
    } else {
        builder.setSmallIcon(R.drawable.ic_notifs_kitkat_issue);
    }

    NotificationManager notificationManager = (NotificationManager) c
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(TAG_PREFIX + notice.type, 0, builder.build());
}

From source file:com.embeddedlog.LightUpDroid.timer.TimerReceiver.java

private void updateNextTimesup(Context context) {
    TimerObj t = getNextRunningTimer(mTimers, false, Utils.getTimeNow());
    long nextTimesup = (t == null) ? -1 : t.getTimesupTime();
    int timerId = (t == null) ? -1 : t.mTimerId;

    Intent intent = new Intent();
    intent.setAction(Timers.TIMES_UP);/*from ww w .j  a  v  a2s .com*/
    intent.setClass(context, TimerReceiver.class);
    if (!mTimers.isEmpty()) {
        intent.putExtra(Timers.TIMER_INTENT_EXTRA, timerId);
    }
    AlarmManager mngr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent p = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);
    if (t != null) {
        if (Utils.isKitKatOrLater()) {
            mngr.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        } else {
            mngr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextTimesup, p);
        }
        if (Timers.LOGGING) {
            Log.d(TAG, "Setting times up to " + nextTimesup);
        }
    } else {
        mngr.cancel(p);
        if (Timers.LOGGING) {
            Log.v(TAG, "no next times up");
        }
    }
}