Example usage for android.app TaskStackBuilder addParentStack

List of usage examples for android.app TaskStackBuilder addParentStack

Introduction

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

Prototype

public TaskStackBuilder addParentStack(ComponentName sourceActivityName) 

Source Link

Document

Add the activity parent chain as specified by the android.R.attr#parentActivityName parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.

Usage

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void startStatusBar(final Context context) {
    if (isStatusBarShown)
        return;//  ww  w . j  a v a 2s .  c  om

    // At this moment Inspector still doesn't have a current level assigned
    DataEstimator estimator = new DataEstimator();
    estimator.getCurrentStatus(context);

    int now = Battery.getBatteryCurrentNow(context);
    int level = estimator.getLevel();
    String title = context.getString(R.string.now) + ": " + now + " mA";
    String text = context.getString(R.string.notif_batteryhub_running);

    sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text)
            .setAutoCancel(false).setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (level < 100) {
        sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, 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(context);
    // 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);
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}

From source file:com.matze5800.paupdater.Functions.java

public static void Notify(Context context, String text) {
    Log.i("notify", text);
    Notification.Builder nBuilder;
    nBuilder = new Notification.Builder(context);
    Intent resultIntent = new Intent(context, Cancel.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(Cancel.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    nBuilder.setContentIntent(resultPendingIntent);
    nBuilder.setSmallIcon(R.drawable.ic_launcher);
    nBuilder.setContentTitle("PA Updater");
    nBuilder.setContentText(text);//  www .  j ava 2 s .c om
    nBuilder.setAutoCancel(false);
    nBuilder.setOngoing(true);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, nBuilder.build());
}

From source file:com.firescar96.nom.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void Notify(String notificationTitle, String notificationMessage, Bundle data, int id,
        boolean annoy) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(thisService)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle)
            .setContentText(notificationMessage).setAutoCancel(true);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(thisService, MainActivity.class);
    resultIntent.putExtras(data);/*from w w  w  .j a va2s  . com*/

    // 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(thisService);
    // 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);
    if (annoy) {
        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        mBuilder.setSound(alarmSound);
        long[] pattern = { 50, 100, 10, 100, 10, 200 };
        mBuilder.setVibrate(pattern);
    }
    NotificationManager mNotificationManager = (NotificationManager) thisService
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:com.polkapolka.bluetooth.le.DeviceControlActivity.java

public static void showNotificationInMenu(Context context) {

    // variables/* w  w  w.j  a v  a2s . c  om*/
    long currentTime = System.currentTimeMillis();

    // guard: check if we should wait
    if (currentTime - lastNotificationTime < NOTIFICATION_DELAY) {
        return;
    }

    lastNotificationTime = currentTime;

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(context.getString(R.string.NotifationTitle))
            .setContentText(context.getString(R.string.NotificationSubtitle))
            .setTicker(context.getString(R.string.BadPostureTicker)).setSmallIcon(R.drawable.icon);
    // Define that we have the intention of opening MoreInfoNotification
    Intent moreInfoIntent = new Intent(context, userActivity.class);

    // Used to stack tasks across activites so we go to the proper place when back is clicked
    TaskStackBuilder tStackBuilder = TaskStackBuilder.create(context);

    // Add all parents of this activity to the stack
    tStackBuilder.addParentStack(DeviceControlActivity.class);

    // Add our new Intent to the stack
    tStackBuilder.addNextIntent(moreInfoIntent);
    // default_all -> vibrate light and sound DEFAULT_VIBRATE -> only vibration even with sound on.
    notificationBuilder.setDefaults(Notification.DEFAULT_ALL);

    notificationBuilder.setAutoCancel(true);

    // Define an Intent and an action to perform with it by another application
    // FLAG_UPDATE_CURRENT : If the intent exists keep it but update it if needed
    PendingIntent pendingIntent = tStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // Defines the Intent to fire when the notification is clicked

    notificationBuilder.setContentIntent(pendingIntent);

    // Gets a NotificationManager which is used to notify the user of the background event

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

    // Post the notification
    notificationManager.notify(notifID, notificationBuilder.build());

}

From source file:com.luan.thermospy.android.core.NotificationHandler.java

private NotificationCompat.Builder createBuilder(Context c, String temperature, boolean playSound) {
    String text = "Current temperature is " + temperature;

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true).setContentTitle("Thermospy")
            .setContentText(text).setOnlyAlertOnce(false)
            .setSmallIcon(R.drawable.ic_stat_action_assignment_late);

    Uri alarmSound = null;/*w w  w.  ja  va  2  s .  c  om*/
    if (playSound) {
        alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    }

    mBuilder.setSound(alarmSound);

    Intent resultIntent = new Intent(c, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(c);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    return mBuilder;
}

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.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.lambdasoup.quickfit.persist.FitApiFailureResolutionService.java

private void handleErrorInBackground(ConnectionResult connectionResult, int startId) {
    if (!connectionResult.hasResolution()) {
        // Show the localized error notification
        GoogleApiAvailability.getInstance().showErrorNotification(this, connectionResult.getErrorCode());
        return;/* w ww .  ja  v a2  s  .  c  o  m*/
    }
    // The failure has a resolution. Resolve it.
    // Called typically when the app is not yet authorized, and an
    // authorization dialog is displayed to the user.
    Intent resultIntent = new Intent(this, WorkoutListActivity.class);
    resultIntent.putExtra(WorkoutListActivity.EXTRA_PLAY_API_CONNECT_RESULT, connectionResult);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(WorkoutListActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(getResources().getString(R.string.permission_needed_play_service_title))
            .setContentText(getResources().getString(R.string.permission_needed_play_service))
            .setSmallIcon(R.drawable.common_ic_googleplayservices).setContentIntent(resultPendingIntent)
            .setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setCategory(Notification.CATEGORY_ERROR);
    }

    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
            .notify(Constants.NOTIFICATION_PLAY_INTERACTION, notificationBuilder.build());
    stopSelfResult(startId);
}

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   www  .j a v  a  2  s  .  c o  m*/
}

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);
}