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.wizardsofm.deskclock.data.TimerNotificationBuilderPreN.java

@Override
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final long remainingTime = timer.getRemainingTime();

    // Generate some descriptive text, a title, and some actions based on timer states.
    final String contentText;
    final String contentTitle;
    @DrawableRes/* w  w w.  j  a v a  2  s  .  c  om*/
    int firstActionIconId, secondActionIconId = 0;
    @StringRes
    int firstActionTitleId, secondActionTitleId = 0;
    Intent firstActionIntent, secondActionIntent = null;

    if (unexpired.size() == 1) {
        contentText = formatElapsedTimeUntilExpiry(context, remainingTime);

        if (timer.isRunning()) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_notification_label);
            } else {
                contentTitle = timer.getLabel();
            }

            firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_pause_24dp;
            firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_pause;
            firstActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_add_24dp;
            secondActionTitleId = com.wizardsofm.deskclock.R.string.timer_plus_1_min;
            secondActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());
        } else {
            // Single timer is paused.
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timer_paused);

            firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_start_24dp;
            firstActionTitleId = com.wizardsofm.deskclock.R.string.sw_resume_button;
            firstActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            secondActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp;
            secondActionTitleId = com.wizardsofm.deskclock.R.string.sw_reset_button;
            secondActionIntent = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());
        }
    } else {
        if (timer.isRunning()) {
            // At least one timer is running.
            final String timeRemaining = formatElapsedTimeUntilExpiry(context, remainingTime);
            contentText = context.getString(com.wizardsofm.deskclock.R.string.next_timer_notif, timeRemaining);
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_in_use, unexpired.size());
        } else {
            // All timers are paused.
            contentText = context.getString(com.wizardsofm.deskclock.R.string.all_timers_stopped_notif);
            contentTitle = context.getString(com.wizardsofm.deskclock.R.string.timers_stopped,
                    unexpired.size());
        }

        firstActionIconId = com.wizardsofm.deskclock.R.drawable.ic_reset_24dp;
        firstActionTitleId = com.wizardsofm.deskclock.R.string.timer_reset_all;
        firstActionIntent = TimerService.createResetUnexpiredTimersIntent(context);
    }

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS)
            .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId())
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL,
                    com.wizardsofm.deskclock.R.string.label_notification);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setOngoing(true)
            .setLocalOnly(true).setShowWhen(false).setAutoCancel(false).setContentText(contentText)
            .setContentTitle(contentTitle).setContentIntent(pendingShowApp)
            .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer)
            .setPriority(NotificationCompat.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background));

    final PendingIntent action1 = Utils.pendingServiceIntent(context, firstActionIntent);
    final String action1Title = context.getString(firstActionTitleId);
    builder.addAction(firstActionIconId, action1Title, action1);

    if (secondActionIntent != null) {
        final PendingIntent action2 = Utils.pendingServiceIntent(context, secondActionIntent);
        final String action2Title = context.getString(secondActionTitleId);
        builder.addAction(secondActionIconId, action2Title, action2);
    }

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Intent updateNotification = TimerService.createUpdateNotificationIntent(context);
    if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) {
        // Schedule a callback to update the time-sensitive information of the running timer.
        final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

        final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS;
        final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange;
        TimerModel.schedulePendingIntent(am, triggerTime, pi);
    } else {
        // Cancel the update notification callback.
        final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE);
        if (pi != null) {
            am.cancel(pi);
            pi.cancel();
        }
    }

    return builder.build();
}

From source file:com.gcmandroid_uniqueid1010.nemo.NirapodNouvromon.gcm.MyGcmPushReceiver.java

private void sendNotification(String message, String title) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int requestCode = 0;

    int icon = this.getResources().getIdentifier("app_icon", "drawable", this.getPackageName());

    if (alertClass_global.getIs_resolved() == 1) {
        icon = this.getResources().getIdentifier("danger", "drawable", this.getPackageName());
    }/* ww w .ja v  a 2  s. c  o m*/
    if (alertClass_global.getIs_resolved() == 2) {
        icon = this.getResources().getIdentifier("relax", "drawable", this.getPackageName());
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
            //  .setSmallIcon(R.mipmap.ic_launcher)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message).setAutoCancel(true)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
}

From source file:kr.ds.travel.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  w w  w .  jav a 2s  .c  om*/
 */
private void sendNotification(String message, String push_type) {
    Intent intent = new Intent(this, IntroActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("type", push_type);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder;
    if (isvibrate) {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon)
                .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    } else {
        notificationBuilder = new NotificationCompat.Builder(this)
                .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon)
                .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 })
                .setContentIntent(pendingIntent);
    }

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

    notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build());
}

From source file:com.poguico.palmabici.network.synchronizer.NetworkStationAlarm.java

public void showNotification(Station station) {
    SharedPreferences mPrefs;//from   w ww  .j av a2 s.c  o  m
    SharedPreferences.Editor edit;
    String message = Formatter.formatBikesAvailableMessage(context, station);
    Bitmap bigIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.palmabici_bw);
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK),
            PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.bike)
            .setLargeIcon(bigIcon).setContentTitle("PalmaBici").setContentText(message)
            .setLights(0x0000ff00, 1000, 1000).setTicker(message).setSound(uri).setAutoCancel(true);

    NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    mBuilder.setContentIntent(pendingIntent);

    mPrefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    edit = mPrefs.edit();
    edit.putInt(PREFS_SHOWN_STATION, station.getId());
    edit.commit();

    mgr.notify(0, mBuilder.build());
}

From source file:com.fast.van.cloudmessaging.MyGcmListenerService.java

private void sendNotification(String message) {

    /*Intent intent;/*w  w w.j  av a 2  s .c  o  m*/
    if(notificationType!=null&&notificationType.equals("DRIVER_ASSIGNED")){
        intent=new Intent(this,ActivityNewRequest.class);
    }else{
            
    }*/

    Intent intent = new Intent(this, ActivityOrderStateNotification.class);
    intent.putExtra("message", message);
    if (BaseActivity.isForeGround()) {

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        return;
    }

    BaseUtils.removeCancelNotification(this);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.notification).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(128 /* ID of notification */, notificationBuilder.build());
}

From source file:com.itime.team.itime.services.ITimeGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM message received./*from  www  .  ja va 2s.  co  m*/
 */
private void sendNotification(Bundle data) {
    ParcelableMessage message = new ParcelableMessage(data);
    if (message.messageType == null) {
        return;
    }

    Intent intent = new Intent(this, CheckLoginActivity.class);
    // Set ACTION_MAIN and CATEGORY_LAUNCHER is the key!
    // Even though CheckLoginActivity is finish and no longer exist, the app will return to the
    // foreground and CheckLoginActivity would not be created again. Demonstrated in the logcat
    // where on CheckLoginActivity onCreate, onResume.
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    // Do add this flags otherwise it will clear all the activity in the stack
    //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    String messageTitle = data.getString("alert", "ITime Message");
    String messageBody = data.getString("message_body", "ITime Message");
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notifications_active_black).setContentTitle(messageTitle)
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(NotificationID.getID() /* ID of notification */, notificationBuilder.build());
}

From source file:com.groundupworks.wings.core.WingsService.java

/**
 * Sends a {@link com.groundupworks.wings.WingsEndpoint.ShareNotification} to the notification bar.
 *//*  ww w  .j  av  a  2  s . c o m*/
private void sendNotification(WingsEndpoint.ShareNotification wingsNotification) {
    // Construct pending intent. The wrapped Intent must not be null as some versions of Android require it.
    Intent intent = wingsNotification.getIntent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    // Construct notification.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    Notification notification = builder.setSmallIcon(R.drawable.wings__notification)
            .setContentTitle(wingsNotification.getTitle()).setContentText(wingsNotification.getMessage())
            .setTicker(wingsNotification.getTicker()).setAutoCancel(true).setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent).build();

    // Send notification.
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if (notificationManager != null) {
        notificationManager.notify(wingsNotification.getId(), notification);
    }
}

From source file:com.android.deskclock.data.TimerNotificationBuilderN.java

@Override
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) {
    final Timer timer = unexpired.get(0);
    final int count = unexpired.size();

    // Compute some values required below.
    final boolean running = timer.isRunning();
    final Resources res = context.getResources();

    final long base = getChronometerBase(timer);
    final String pname = context.getPackageName();
    final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content);
    content.setChronometerCountDown(R.id.chronometer, true);
    content.setChronometer(R.id.chronometer, base, null, running);

    final List<Notification.Action> actions = new ArrayList<>(2);

    final CharSequence stateText;
    if (count == 1) {
        if (running) {
            // Single timer is running.
            if (TextUtils.isEmpty(timer.getLabel())) {
                stateText = res.getString(R.string.timer_notification_label);
            } else {
                stateText = timer.getLabel();
            }// w  w w. j ava2  s .c  o m

            // Left button: Pause
            final Intent pause = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp);
            final CharSequence title1 = res.getText(R.string.timer_pause);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: +1 Minute
            final Intent addMinute = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp);
            final CharSequence title2 = res.getText(R.string.timer_plus_1_min);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());

        } else {
            // Single timer is paused.
            stateText = res.getString(R.string.timer_paused);

            // Left button: Start
            final Intent start = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp);
            final CharSequence title1 = res.getText(R.string.sw_resume_button);
            final PendingIntent intent1 = Utils.pendingServiceIntent(context, start);
            actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());

            // Right Button: Reset
            final Intent reset = new Intent(context, TimerService.class)
                    .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER)
                    .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId());

            final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp);
            final CharSequence title2 = res.getText(R.string.sw_reset_button);
            final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset);
            actions.add(new Notification.Action.Builder(icon2, title2, intent2).build());
        }
    } else {
        if (running) {
            // At least one timer is running.
            stateText = res.getString(R.string.timers_in_use, count);
        } else {
            // All timers are paused.
            stateText = res.getString(R.string.timers_stopped, count);
        }

        final Intent reset = TimerService.createResetUnexpiredTimersIntent(context);

        final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_reset_24dp);
        final CharSequence title1 = res.getText(R.string.timer_reset_all);
        final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset);
        actions.add(new Notification.Action.Builder(icon1, title1, intent1).build());
    }

    content.setTextViewText(R.id.state, stateText);

    // Intent to load the app and show the timer when the notification is tapped.
    final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS)
            .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId())
            .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, R.string.label_notification);

    final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp,
            PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT);

    return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false)
            .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp)
            .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM)
            .setSmallIcon(R.drawable.stat_notify_timer).setGroup(nm.getTimerNotificationGroupKey())
            .setVisibility(Notification.VISIBILITY_PUBLIC).setStyle(new Notification.DecoratedCustomViewStyle())
            .setActions(actions.toArray(new Notification.Action[actions.size()]))
            .setColor(ContextCompat.getColor(context, R.color.default_background)).build();
}

From source file:au.com.websitemasters.schools.lcps.push.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from   w w  w .j  a  va 2s  . co m
 */

public void sendNotification(String message, Class clas) {

    //load not readed. +1. save em.
    int notReaded = ((SchoolsApplication) getApplicationContext()).loadBadgesCount();
    notReaded++;
    ((SchoolsApplication) getApplicationContext()).saveBadgesCount(notReaded);

    //show it on badge.
    ShortcutBadger.applyCount(getApplicationContext(), notReaded);

    Intent intent = new Intent(this, clas);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo_gray).setContentTitle("Leschenault Catholic Primary School")
            .setContentText(message).setAutoCancel(true).setNumber(notReaded).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

    //push realtime refresh of lists (ANN)
    Intent intentBroadcast = new Intent(BROADCAST_ACTION);
    sendBroadcast(intentBroadcast);
}

From source file:com.owncloud.android.jobs.MediaFoldersDetectionJob.java

private void sendNotification(String contentTitle, String subtitle, Account account, String path, int type) {
    Context context = getContext();
    Intent intent = new Intent(getContext(), SyncedFoldersActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(NotificationJob.KEY_NOTIFICATION_ACCOUNT, account.name);
    intent.putExtra(KEY_MEDIA_FOLDER_PATH, path);
    intent.putExtra(KEY_MEDIA_FOLDER_TYPE, type);
    intent.putExtra(SyncedFoldersActivity.EXTRA_SHOW_SIDEBAR, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context,
            NotificationUtils.NOTIFICATION_CHANNEL_GENERAL)
                    .setSmallIcon(R.drawable.notification_icon)
                    .setLargeIcon(/*w w w . j  ava  2s  .  co  m*/
                            BitmapFactory.decodeResource(context.getResources(), R.drawable.notification_icon))
                    .setColor(ThemeUtils.primaryColor(getContext())).setSubText(account.name)
                    .setContentTitle(contentTitle).setContentText(subtitle)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                    .setAutoCancel(true).setContentIntent(pendingIntent);

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

    if (notificationManager != null) {
        notificationManager.notify(0, notificationBuilder.build());
    }
}