Example usage for android.app TaskStackBuilder addNextIntent

List of usage examples for android.app TaskStackBuilder addNextIntent

Introduction

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

Prototype

public TaskStackBuilder addNextIntent(Intent nextIntent) 

Source Link

Document

Add a new Intent to the task stack.

Usage

From source file:com.conceptberria.wattion.background.MakeNotification.java

/**
 * Para versiones mas alta que JellyBean genera un intent aadiendo en la pila de tareas la actividad {@link ViewPrice}
 * @return el intent//from  w w  w.  ja va  2  s . co m
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private PendingIntent getPendingIntentWithStackBuilder() {
    Intent resultIntent = new Intent(this, ViewPrice.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ViewPrice.class);
    stackBuilder.addNextIntent(resultIntent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:com.android.talkbacktests.testsession.NotificationTest.java

private void showSimpleNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext())
            .setSmallIcon(android.R.drawable.ic_notification_overlay).setAutoCancel(true)
            .setContentTitle(getString(R.string.normal_notification_title))
            .setContentText(getString(R.string.normal_notification_text))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());
    stackBuilder.addParentStack(MainActivity.class);

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build());
}

From source file:com.mienaikoe.deltamonitor.CameraWatcherService.java

private void notifyMessage(String title, String message) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle(title).setContentText(message);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MotionDetectionActivity.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);
    stackBuilder.addParentStack(MotionDetectionActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    if (notifier == null) {
        notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }//from  w  w w  . ja v  a2 s.  c o  m
    notifier.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:org.catnut.service.ComposeTweetService.java

private void fallback(Draft draft, String error) {
    draft.createAt = System.currentTimeMillis();
    getContentResolver().insert(CatnutProvider.parse(Draft.MULTIPLE), Draft.METADATA.convert(draft));
    mBuilder.setContentTitle(getString(R.string.post_fail)).setContentText(error)
            .setTicker(getText(R.string.post_fail)).setProgress(0, 0, false);

    // fallback/*from   w ww  . ja  v a  2s .  c  o m*/
    Intent resultIntent = SingleFragmentActivity.getIntent(this, SingleFragmentActivity.DRAFT);

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
    taskStackBuilder.addParentStack(SingleFragmentActivity.class);
    taskStackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(ID,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent).setAutoCancel(true);
    mNotifyManager.notify(ID, mBuilder.build());
}

From source file:nabhack.localz.receiver.GcmBroadcastReceiver.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_stat_localz).setContentTitle("New Localz deal!!!")
            .setContentText("You have new deal from Localz!!!").setAutoCancel(true);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, DealSummaryActivity_.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(ctx);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(DealSummaryActivity_.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);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    // And notify DealOfTheDayActivity if it is on the foreground
    Intent intent = new Intent();
    intent.setAction("nabhack.localz");
    intent.putExtra("Message", msg);
    ctx.sendBroadcast(intent);// w w  w .j a  v  a  2s.  c o m
}

From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *///w w w . ja va  2s.c  o  m
private void sendNotification(String nameofsensor) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

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

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.drawable.icon)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED)
            .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor)
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.dogtim.recommendation.MainFragment.java

private PendingIntent buildPendingIntent() {
    Intent detailsIntent = new Intent();

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getActivity());
    stackBuilder.addNextIntent(detailsIntent);

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:capstone.se491_phm.gcm.PhmGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*w  w w .  j ava 2 s . c  o  m*/
 */
private void sendNotification(String message) {
    Context context = getBaseContext();
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(Constants.SERVER_IP, message);
    editor.commit();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification).setContentTitle("External Sensor Request")
            .setContentText("A connection request has been made from this ip: " + message
                    + ". Click to allow connection")
            .setSound(defaultSoundUri);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, ExternalSensorActivity.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(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ExternalSensorActivity.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);
    // mId allows you to update the notification later on.
    MainActivity.mNotificationManager.notify(notificationId, mBuilder.build());
}

From source file:com.example.maciej.mytask.MainActivity.java

public void createNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.add)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notification_desc));
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(12, mBuilder.build());
}

From source file:com.ibm.mf.geofence.demo.MyGeofenceReceiver.java

private void sendNotification(Context context, List<MFGeofence> fences, String type) {
    String title = "Geofence: " + type;
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (MFGeofence g : fences) {
        if (count > 0)
            sb.append('\n');
        sb.append(String.format("%s : lat=%.6f; lng=%.6f; radius=%.0f m", g.getName(), g.getLatitude(),
                g.getLongitude(), g.getRadius()));
        count++;//from   w  ww  . j  a  va 2  s.c  o m
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(android.R.drawable.ic_notification_overlay).setContentTitle(title)
            .setContentText(sb.toString());
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MapsActivity.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(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MapsActivity.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) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(notifId.incrementAndGet(), mBuilder.build());
}