Example usage for android.app TaskStackBuilder getPendingIntent

List of usage examples for android.app TaskStackBuilder getPendingIntent

Introduction

In this page you can find the example usage for android.app TaskStackBuilder getPendingIntent.

Prototype

public PendingIntent getPendingIntent(int requestCode, @PendingIntent.Flags int flags) 

Source Link

Document

Obtain a PendingIntent for launching the task constructed by this builder so far.

Usage

From source file:com.PrivacyGuard.Application.Network.FakeVPN.MyVpnService.java

void buildNotification(int notifyId, int frequency, LeakReport leak) {
    String msg = leak.appName + " is leaking " + leak.category.name() + " information";
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_spam)
            .setContentTitle(leak.appName).setContentText(msg).setNumber(frequency).setTicker(msg)
            .setAutoCancel(true);//from  w  w w  .jav a  2 s  .  c om

    Intent ignoreIntent = new Intent(this, ActionReceiver.class);
    ignoreIntent.setAction("Ignore");
    ignoreIntent.putExtra("notificationId", notifyId);
    // use System.currentTimeMillis() to have a unique ID for the pending intent
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),
            (int) System.currentTimeMillis(), ignoreIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.addAction(R.drawable.ic_cancel, "Ignore this kind of leaks", pendingIntent);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, AppSummaryActivity.class);
    resultIntent.putExtra(PrivacyGuard.EXTRA_PACKAGE_NAME, leak.packageName);
    resultIntent.putExtra(PrivacyGuard.EXTRA_APP_NAME, leak.appName);
    resultIntent.putExtra(PrivacyGuard.EXTRA_IGNORE, 0);

    // 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 home screen
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(AppSummaryActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // builds the notification and sends it
    mNotificationManager.notify(notifyId, mBuilder.build());

}

From source file:com.yeldi.yeldibazaar.UpdateService.java

protected void onHandleIntent(Intent intent) {

    receiver = intent.getParcelableExtra("receiver");

    long startTime = System.currentTimeMillis();
    String errmsg = "";
    try {/*from w ww.  jav a 2 s.com*/

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        // See if it's time to actually do anything yet...
        if (isScheduledRun()) {
            long lastUpdate = prefs.getLong("lastUpdateCheck", 0);
            String sint = prefs.getString("updateInterval", "0");
            int interval = Integer.parseInt(sint);
            if (interval == 0) {
                Log.d("FDroid", "Skipping update - disabled");
                return;
            }
            long elapsed = System.currentTimeMillis() - lastUpdate;
            if (elapsed < interval * 60 * 60 * 1000) {
                Log.d("FDroid",
                        "Skipping update - done " + elapsed + "ms ago, interval is " + interval + " hours");
                return;
            }
        } else {
            Log.d("FDroid", "Unscheduled (manually requested) update");
        }

        boolean notify = prefs.getBoolean("updateNotify", false);

        // Grab some preliminary information, then we can release the
        // database while we do all the downloading, etc...
        int prevUpdates = 0;
        int newUpdates = 0;
        List<DB.Repo> repos;
        try {
            DB db = DB.getDB();
            repos = db.getRepos();
        } finally {
            DB.releaseDB();
        }

        // Process each repo...
        List<DB.App> apps = new ArrayList<DB.App>();
        List<Integer> keeprepos = new ArrayList<Integer>();
        boolean success = true;
        boolean changes = false;
        for (DB.Repo repo : repos) {
            if (repo.inuse) {

                sendStatus(STATUS_INFO, getString(R.string.status_connecting_to_repo, repo.address));

                StringBuilder newetag = new StringBuilder();
                String err = RepoXMLHandler.doUpdate(getBaseContext(), repo, apps, newetag, keeprepos, this);
                if (err == null) {
                    String nt = newetag.toString();
                    if (!nt.equals(repo.lastetag)) {
                        repo.lastetag = newetag.toString();
                        changes = true;
                    }
                } else {
                    success = false;
                    err = "Update failed for " + repo.address + " - " + err;
                    Log.d("FDroid", err);
                    if (errmsg.length() == 0)
                        errmsg = err;
                    else
                        errmsg += "\n" + err;
                }
            }
        }

        List<DB.App> acceptedapps = new ArrayList<DB.App>();
        if (!changes && success) {
            Log.d("FDroid", "Not checking app details or compatibility, because all repos were up to date.");
        } else if (changes && success) {

            sendStatus(STATUS_INFO, getString(R.string.status_checking_compatibility));
            List<DB.App> prevapps = ((FDroidApp) getApplication()).getApps();

            DB db = DB.getDB();
            try {

                // Need to flag things we're keeping despite having received
                // no data about during the update. (i.e. stuff from a repo
                // that we know is unchanged due to the etag)
                for (int keep : keeprepos) {
                    for (DB.App app : prevapps) {
                        boolean keepapp = false;
                        for (DB.Apk apk : app.apks) {
                            if (apk.repo == keep) {
                                keepapp = true;
                                break;
                            }
                        }
                        if (keepapp) {
                            DB.App app_k = null;
                            for (DB.App app2 : apps) {
                                if (app2.id.equals(app.id)) {
                                    app_k = app2;
                                    break;
                                }
                            }
                            if (app_k == null) {
                                apps.add(app);
                                app_k = app;
                            }
                            app_k.updated = true;
                            db.populateDetails(app_k, keep);
                            for (DB.Apk apk : app.apks)
                                if (apk.repo == keep)
                                    apk.updated = true;
                        }
                    }
                }

                prevUpdates = db.beginUpdate(prevapps);
                for (DB.App app : apps) {
                    if (db.updateApplication(app))
                        acceptedapps.add(app);
                }
                db.endUpdate();
                if (notify)
                    newUpdates = db.getNumUpdates();
                for (DB.Repo repo : repos)
                    db.writeLastEtag(repo);
            } catch (Exception ex) {
                db.cancelUpdate();
                Log.e("FDroid", "Exception during update processing:\n" + Log.getStackTraceString(ex));
                errmsg = "Exception during processing - " + ex.getMessage();
                success = false;
            } finally {
                DB.releaseDB();
            }

        }

        if (success) {
            File d = DB.getIconsPath(this);
            List<DB.App> toDownloadIcons = null;
            if (!d.exists()) {
                Log.d("FDroid", "Icons were wiped. Re-downloading all of them.");
                d.mkdirs();
                toDownloadIcons = ((FDroidApp) getApplication()).getApps();
            } else if (changes) {
                toDownloadIcons = acceptedapps;
            }
            if (toDownloadIcons != null) {

                // Create a .nomedia file in the icons directory. For
                // recent Android versions this isn't necessary, because
                // they recognise the cache location. Older versions don't
                // though.
                File f = new File(d, ".nomedia");
                if (!f.exists()) {
                    try {
                        f.createNewFile();
                    } catch (Exception e) {
                        Log.d("FDroid", "Failed to create .nomedia");
                    }
                }

                sendStatus(STATUS_INFO, getString(R.string.status_downloading_icons));
                for (DB.App app : toDownloadIcons)
                    getIcon(app, repos);
            }
        }

        if (success && changes)
            ((FDroidApp) getApplication()).invalidateAllApps();

        if (success && changes && notify && (newUpdates > prevUpdates)) {
            Log.d("FDroid", "Notifying updates. Apps before:" + prevUpdates + ", apps after: " + newUpdates);
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.icon)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon))
                    .setAutoCancel(true).setContentTitle(getString(R.string.fdroid_updates_available));
            Intent notifyIntent = new Intent(this, FDroid.class).putExtra(FDroid.EXTRA_TAB_UPDATE, true);
            if (newUpdates > 1) {
                mBuilder.setContentText(getString(R.string.many_updates_available, newUpdates));

            } else {
                mBuilder.setContentText(getString(R.string.one_update_available));
            }
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this).addParentStack(FDroid.class)
                    .addNextIntent(notifyIntent);
            PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(pendingIntent);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(1, mBuilder.build());
        }

        if (!success) {
            if (errmsg.length() == 0)
                errmsg = "Unknown error";
            sendStatus(STATUS_ERROR, errmsg);
        } else {
            sendStatus(STATUS_COMPLETE);
            Editor e = prefs.edit();
            e.putLong("lastUpdateCheck", System.currentTimeMillis());
            e.commit();
        }

    } catch (Exception e) {
        Log.e("FDroid", "Exception during update processing:\n" + Log.getStackTraceString(e));
        if (errmsg.length() == 0)
            errmsg = "Unknown error";
        sendStatus(STATUS_ERROR, errmsg);
    } finally {
        Log.d("FDroid", "Update took " + ((System.currentTimeMillis() - startTime) / 1000) + " seconds.");
        receiver = null;
    }
}

From source file:com.hollandhaptics.babyapp.BabyService.java

/**
 * @param _message The message to show.// w ww .  ja  va  2  s.c o m
 * @brief Makes a notification for the user
 */
private void notifyUser(String _message) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Baby App").setContentText(_message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.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
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    // mId = 0
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java

/**
 * Notifies the user that fresh news updates are now available.
 *//*from ww  w. j av a  2  s.co  m*/
private void sendNewsNotification(Context context) {
    // Create the intent to open the app when the user taps on the notification.
    Intent mainIntent = new Intent(context, MainActivity.class);

    // Create the stack builder object.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    // Add the intent to the top of the stack.
    stackBuilder.addNextIntent(mainIntent);

    // Get a pending intent containing the entire back stack.
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the notification builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Set the pending intent onto the notification.
    builder.setContentIntent(pendingIntent);

    // Set the notification to automatically dismiss after the user taps it.
    builder.setAutoCancel(true);

    // Set the notification title and text.
    builder.setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.msg_notification_text));

    // Set the notification ticker.
    builder.setTicker(context.getString(R.string.msg_notification_text));

    // Set the notification large and small icons.
    builder.setSmallIcon(R.drawable.ic_notify_small)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_notify_large));

    // Send the notification.
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(context.NOTIFICATION_SERVICE);
    notificationManager.notify(NEWS_NOTIFICATION_ID, builder.build());
}

From source file:com.partner.common.updater.ApkDownloadUtil.java

/**
 * ?/*from ww  w .  j  a v  a 2s.  c om*/
 * @param context
 * @param targetClass
 */
private void showAppDownloadNotify(Context context, Class<?> parentClass, Class<?> targetClass) {
    mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // show notify
    Intent notifyIntent = new Intent(context, targetClass);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack
    if (parentClass != null) {
        stackBuilder.addNextIntent(new Intent(context, parentClass));
    }
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(notifyIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder = new NotificationCompat.Builder(context);
    mBuilder.setContentTitle(appName).setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(resultPendingIntent);
    mBuilder.setProgress(100, 0, false);
    mNotifyManager.notify(appName.hashCode(), mBuilder.build());
}

From source file:com.y59song.PrivacyGuard.MyVpnService.java

@Override
public void notify(String appName, String msg) {
    isLocation(appName, msg);/*from  w  w  w  .  j  a v a  2 s  . c om*/

    boolean ignored = false;

    if (isIgnored(appName, msg)) {
        ignored = true;
    }

    if (findNotificationId(appName, msg) >= 0) {
        updateNotification(appName, msg);
        return;
    }

    // -----------------------------------------------------------------------
    // Database Entry
    DatabaseHandler db = new DatabaseHandler(this);
    db.addLeak(new DataLeak(mId, appName, msg, 1, dateFormat.format(new Date())));

    // -----------------------------------------------------------------------

    if (ignored) {
        return;
    }

    int notifyId = findNotificationId(appName, msg);
    int generalNotifyId = findGeneralNotificationId(appName);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.notify)
            .setContentTitle("Privacy Guard").setTicker(appName + " " + msg)
            .setContentText(appName + " " + msg);
    if (DEBUG)
        Log.i(TAG, msg);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, DetailsActivity.class);

    List<LocationLeak> leakList = db.getLocationLeaks(appName);
    resultIntent.putExtra(EXTRA_APP, appName);
    resultIntent.putExtra(EXTRA_SIZE, String.valueOf(leakList.size()));
    for (int i = 0; i < leakList.size(); i++) {
        resultIntent.putExtra(EXTRA_DATA + i, leakList.get(i).getLocation()); // to pass values between activities
    }

    // ------------------------------------------------
    Intent intent = new Intent(this, ActionReceiver.class);
    intent.setAction("Ignore");
    intent.putExtra("appName", appName);
    intent.putExtra("notificationId", notifyId);

    // use System.currentTimeMillis() to have a unique ID for the pending intent
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),
            (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.addAction(R.drawable.ignore, "Ignore", pendingIntent);
    // ------------------------------------------------

    // 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 home screen
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(DetailsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // mId updates the notification later on.
    mNotificationManager.notify(generalNotifyId, mBuilder.build());
    mId++;
}

From source file:com.y59song.PrivacyGuard.MyVpnService.java

@Override
public void updateNotification(String appName, String msg) {
    DatabaseHandler db = new DatabaseHandler(this);

    boolean ignored = false;

    if (isIgnored(appName, msg)) {
        ignored = true;//from   ww  w .  j  a v  a 2 s.c o  m
    }

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

    int notifyId = findNotificationId(appName, msg);
    int generalNotifyId = findGeneralNotificationId(appName);

    NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this)
            .setContentText("Number of leaks: " + findNotificationCounter(appName, msg))
            .setContentTitle(appName + " " + msg).setTicker(appName + " " + msg)
            .setSmallIcon(R.drawable.notify);

    // ------------------------------------------------------------------------------------
    // Currently initiates a new activity instance each time, should recycle if already open
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, DetailsActivity.class); // should actually be DetailsActivity.class

    List<LocationLeak> leakList = db.getLocationLeaks(appName);
    resultIntent.putExtra(EXTRA_APP, appName);
    resultIntent.putExtra(EXTRA_SIZE, String.valueOf(leakList.size()));
    for (int i = 0; i < leakList.size(); i++) {
        resultIntent.putExtra(EXTRA_DATA + i, leakList.get(i).getLocation()); // to pass values between activities
    }

    // 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
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(DetailsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotifyBuilder.setContentIntent(resultPendingIntent);

    // ------------------------------------------------------------------------------------
    // Creates an explicit intent for an Activity in your app
    Intent intent = new Intent(this, ActionReceiver.class);
    intent.setAction("Ignore");
    intent.putExtra("appName", appName);
    intent.putExtra("notificationId", notifyId);

    // use System.currentTimeMillis() to have a unique ID for the pending intent
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(),
            (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
    mNotifyBuilder.addAction(R.drawable.ignore, "Ignore", pendingIntent);

    // ------------------------------------------------------------------------------------
    // Set Notification Style to Expanded
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    String[] events = new String[findNotificationCounter(appName, msg)];
    if (generalNotifyId >= 0 && !ignored) {
        // Because the ID remains unchanged, the existing notification is updated.
        Log.i(TAG, "NOTIFYID IS SUCCESSFULL" + notifyId);
        mNotificationManager.notify(generalNotifyId, mNotifyBuilder.build());
    } else {
        Log.i(TAG, "NOTIFYID IS FAILING" + notifyId);
    }

    // -----------------------------------------------------------------------
    // Database Entry

    db.addLeak(new DataLeak(notifyId, appName, msg, events.length, dateFormat.format(new Date())));

    // -----------------------------------------------------------------------
}

From source file:com.kyleszombathy.sms_scheduler.Home.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "Activity View Created");

    // Setting up transitions
    getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
    getWindow().setExitTransition(new Fade());

    setContentView(R.layout.activity_home);

    Toolbar toolbar = (Toolbar) findViewById(R.id.SMSScheduler_Toolbar);
    setActionBar(toolbar);//ww w .j  a  v a  2s.  c om

    populateDatasets();
    setUpRecyclerView();

    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter("custom-event-name"));

    parentView = findViewById(R.id.Home_coordLayout);

    prefs = getSharedPreferences("com.kyleszombathy.sms_scheduler", MODE_PRIVATE);

    // Floating action button start activity
    findViewById(R.id.Home_fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Random alarm number
            int alarmNumber = getRandomInt(MIN_INT, MAX_INT);

            Intent intent = new Intent(new Intent(Home.this, AddMessage.class));
            Bundle extras = new Bundle();
            extras.putInt(ALARM_EXTRA, alarmNumber);
            extras.putBoolean(EDIT_MESSAGE_EXTRA, false);
            intent.putExtras(extras);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(Home.this);
            stackBuilder.addParentStack(AddMessage.class);
            stackBuilder.addNextIntent(intent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            Log.d(TAG, "Starting Activity AddMessage");

            startActivityForResult(intent, NEW_MESSAGE,
                    ActivityOptions.makeSceneTransitionAnimation(Home.this).toBundle());
        }
    });
}

From source file:rtdc.android.presenter.InCallActivity.java

@Override
protected void onCreate(android.os.Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_in_call);

    // Force screen to stay on during the call

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    if (getResources().getBoolean(R.bool.isTablet))
        AndroidVoipController.get().setSpeaker(true);

    if (AndroidVoipController.get().isReceivingRemoteVideo() || AndroidVoipController.get().isVideoEnabled()) {
        displayVideo();//w  ww  . jav a 2  s.  c o  m
    } else {
        displayAudio();
    }

    // Build the intent that will be used by the notification

    Intent resultIntent = new Intent(this, InCallActivity.class);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Build stack trace for the notification

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(AndroidBootstrapper.getAppContext());
    stackBuilder.addParentStack(InCallActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    // Build notification

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_phone_white_24dp).setContentTitle(ResBundle.get().rtdcTitle())
            .setContentText(ResBundle.get()
                    .inCallWith(AndroidVoIPThread.getInstance().getCall().getFrom().getDisplayName()));
    PendingIntent inCallPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(inCallPendingIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(IN_CALL_NOTIFICATION_ID, mBuilder.build());

    AndroidVoIPThread.getInstance().addVoIPListener(this);
}

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/*  w  w w .  ja v  a 2 s  .co 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());
}