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.ph1ash.dexter.beeplepaper.BeeplePaperService.java

protected void displayLoginNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.common_full_open_on_phone).setContentTitle("BeeplePaper - Verify Login")
            .setContentText("Verify your Facebook login for to allow BeeplePaper to update.");

    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_ONE_SHOT);
    mBuilder.setContentIntent(resultPendingIntent);
    Notification notif = mBuilder.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, notif);
}

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 va 2 s .  co  m*/
    notifier.notify(NOTIFICATION_ID, mBuilder.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: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  www.j  a  va 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);//from   w  w  w. j ava  2s  . co m
}

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  ww.  j  a va 2  s  .  c  om*/
 */
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.android.example.leanback.fastlane.RecommendationsService.java

private PendingIntent buildPendingIntent(Video video) {
    Intent detailsIntent = new Intent(this, PlayerActivity.class);
    detailsIntent.putExtra(Video.INTENT_EXTRA_VIDEO, video);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(VideoDetailsActivity.class);
    stackBuilder.addNextIntent(detailsIntent);
    // Ensure a unique PendingIntents, otherwise all recommendations end up with the same
    // PendingIntent
    detailsIntent.setAction(Long.toString(video.getId()));

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

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 .  java 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());
}