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.fimo_pitch.main.MainActivity.java

private void makeNotification(Context context, String title, String content) {
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri)
            .setPriority(Notification.PRIORITY_HIGH).setContentText(content);
    Intent resultIntent = new Intent(context, MainActivity.class);
    userModel = getUserModel();//from w ww  .j a v  a2s.  c  o  m
    resultIntent.putExtra(CONSTANT.KEY_USER, userModel);
    resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true");
    TaskStackBuilder stackBuilder = null;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(FirstActivity.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(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(ZAQ500);
    } else {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(10, mBuilder.build());
        //            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        //            v.vibrate(500);
    }
}

From source file:com.radiusnetworks.scavengerhunt.ScavengerHuntApplication.java

private void sendNotification() {
    try {//  ww  w . j a va 2 s  .c  om
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.sh_notification_title))
                .setContentText(getString(R.string.sh_notification_text)).setVibrate(VIBRATOR_PATTERN)
                .setSmallIcon(R.drawable.sh_notification_icon).setAutoCancel(true);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        Intent notificationIntent = new Intent(this, TargetCollectionActivity.class);
        notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        stackBuilder.addNextIntent(notificationIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, builder.build());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:at.aec.solutions.checkmkagent.AgentService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.v(TAG, "onCreate");

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
    m_wakeLock.acquire();// w ww  .ja  v a2s  .c  o m

    //Copy busybox binary to app directory
    if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled",
            false)) {
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                .putBoolean("bbinstalled", true).commit();

        // There is also String[] Build.SUPPORTED_ABIS from API 21 on and
        // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there
        String arch = System.getProperty("os.arch");
        Log.v(TAG, arch);
        if (arch.equals("armv7l")) {
            copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox");
        }
        if (arch.equals("i686")) {
            copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox");
        }

        //         copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64");
        changeBusyboxPermission();
    }

    socketServerThread = new Thread(new SocketServerThread());
    socketServerThread.setName("CheckMK-Agent ServerThread");
    socketServerThread.start();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.")
            .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure.");

    Intent resultIntent = new Intent(this, ConfigureActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ConfigureActivity.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.
    Notification notify = mBuilder.build();
    notify.flags |= Notification.FLAG_NO_CLEAR;

    mNotificationManager.notify(mId, notify);
}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void notifyGooglePlay() {
    int idGooglePlay = 12345;
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.to_google_play));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, ToGooglePlayActivity.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(ToGooglePlayActivity.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.
    mNotificationManager.notify(idGooglePlay, mBuilder.build());

}

From source file:com.ithinkbest.taipeiok.NavigationDrawerActivity.java

private void notifyAppWebpage() {
    int idGooglePlay = 12346;
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.to_app_webpage));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, ToAppWebpageActivity.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(ToAppWebpageActivity.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.
    mNotificationManager.notify(idGooglePlay, mBuilder.build());

}

From source file:br.com.Utilitarios.WorkUpService.java

public void criarNotificacoes(Notificacoes n, String titulo, String texto, String ticker, String tipo,
        String extra) {/*from  ww w.  j a va  2s.c o m*/

    // Build notification
    NotificationCompat.Builder noti = new NotificationCompat.Builder(this);
    noti.setContentTitle(titulo);
    noti.setContentText(texto);
    noti.setTicker(ticker);
    noti.setSmallIcon(R.drawable.ic_launcher);
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    noti.setSound(alarmSound);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent resultIntent = null;
    if (tipo.equals("novoPersonal")) {
        // Creates an expnovaAvaliacaolicit intent for an Activity in your app
        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "aluno");
    }

    if (tipo.equals("novoAluno")) {

        resultIntent = new Intent(this, AceitarRejeitarAmigo.class);
        resultIntent.putExtra("usuario", n.getOrigemNotificacao());
        resultIntent.putExtra("tipo", "personal");

    }

    if (tipo.equals("novaAula")) {
        // Creates an explicit intent for an Activity in your app
        resultIntent = new Intent(this, ConfirmarAula.class);
        resultIntent.putExtra("codAula", extra);
    }

    //This ensures that navigating backward from the Activity leads out of the app to Home page
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    if (tipo.equals("novoPersonal") || tipo.equals("novoAluno")) {
        // Adds the back stack for the Intent
        stackBuilder.addParentStack(AceitarRejeitarAmigo.class);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT //can only be used once
        );
        // start the activity when the user clicks the notification text
        noti.setContentIntent(resultPendingIntent);
    }

    // pass the Notification object to the system
    notificationManager.notify(0, noti.build());

    n.visualizarNotificacao(n.getCodNotificacao());

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

From source file:com.android.mms.transaction.MessagingNotification.java

private static void notifyFailed(Context context, boolean isDownload, long threadId, boolean noisy) {
    // TODO factor out common code for creating notifications
    boolean enabled = MessagingPreferenceActivity.getNotificationEnabled(context);
    if (!enabled) {
        return;//from   w w w.  ja v  a2 s . com
    }

    // Strategy:
    // a. If there is a single failure notification, tapping on the notification goes
    //    to the compose view.
    // b. If there are two failure it stays in the thread view. Selecting one undelivered
    //    thread will dismiss one undelivered notification but will still display the
    //    notification.If you select the 2nd undelivered one it will dismiss the notification.
    int totalFailedCount = getUndeliveredMessageCount(context);

    Intent failedIntent;
    Notification notification = new Notification();
    String title;
    String description;
    if (totalFailedCount > 1) {
        description = context.getString(R.string.notification_failed_multiple,
                Integer.toString(totalFailedCount));
        title = context.getString(R.string.notification_failed_multiple_title);
    } else {
        title = isDownload ? context.getString(R.string.message_download_failed_title)
                : context.getString(R.string.message_send_failed_title);

        description = context.getString(R.string.message_failed_body);
    }

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    // Get failed intent by folder mode or conversation mode.
    if (MessageUtils.isMailboxMode()) {
        failedIntent = getFailedIntentFromFolderMode(context, totalFailedCount, isDownload);
        if (failedIntent == null) {
            return;
        } else if (isDownload) {
            // When isDownload is true, the valid threadId is passed into this function.
            failedIntent.putExtra(FAILED_DOWNLOAD_FLAG, true);
        } else {
            failedIntent.putExtra(UNDELIVERED_FLAG, true);
        }
    } else {
        failedIntent = getFailedIntentFromConversationMode(context, isDownload, threadId);
    }

    taskStackBuilder.addNextIntent(failedIntent);

    notification.icon = R.drawable.stat_notify_sms_failed;

    notification.tickerText = title;

    notification.setLatestEventInfo(context, title, description,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    if (noisy) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        boolean vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE,
                false /* don't vibrate by default */);
        if (vibrate) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
        }

        String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
        notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
    }

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

    if (isDownload) {
        notificationMgr.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification);
    } else {
        notificationMgr.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification);
    }
}

From source file:ua.mkh.weather.MainActivity.java

private void create_notif() {
    // TODO Auto-generated method stub
    // Prepare intent which is triggered if the
    // notification is selected
    String tittle = textView3.getText().toString();
    String subject = textView3.getText().toString();
    String body = "";
    /*// w  w w .  ja v a 2  s.  c  o m
    NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis());
    PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
            
    notify.setLatestEventInfo(getApplicationContext(),subject,body,pending);
    notif.notify(0, notify);
            
            
    final NotificationManager mgr=
    (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note=new Notification((Integer)img1.getTag(),
      "",
                                                System.currentTimeMillis());
                 
        // This pending intent will open after notification click
        PendingIntent i=PendingIntent.getActivity(this, 0,
                                        new Intent(),
                                        0);
                 
        note.setLatestEventInfo(this, tittle,
      "", i);
                 
        //After uncomment this line you will see number of notification arrived
        //note.number=2;
        mgr.notify(1, note);
                
                
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        Resources r = getResources();
        Notification notification = new NotificationCompat.Builder(this)
        .setTicker("Tiket")
        .setSmallIcon(android.R.drawable.ic_menu_report_image)
        .setContentTitle("Title")
        .setContentText("Context Text")
        .setContentIntent(pi)
        .setAutoCancel(true)
        .build();
            
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    */

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews);
    // 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);
    remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
    remoteViews.setTextViewText(R.id.textView1, nnn);
    remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white));
    remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag());
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.  
    mNotificationManager.notify(100, mBuilder.build());

}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processAuthenticationError(final Jaxmpp jaxmpp) {
    Log.e(TAG, "Invalid credentials of account " + jaxmpp.getSessionObject().getUserBareJid());
    jaxmpp.getSessionObject().setUserProperty("CC:DISABLED", true);

    String title = getString(R.string.notification_credentials_error_title,
            jaxmpp.getSessionObject().getUserBareJid().toString());
    String text = getString(R.string.notification_certificate_error_text);

    Intent resultIntent = new Intent(this, LoginActivity.class);
    resultIntent.putExtra("account_name", jaxmpp.getSessionObject().getUserBareJid().toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(android.R.drawable.stat_notify_error).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xffff0000, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("error:" + jaxmpp.getSessionObject().getUserBareJid().toString()).hashCode(),
            builder.build());//from w  w  w  .j  a  v a  2  s .c om
}

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processCertificateError(final Jaxmpp jaxmpp,
        final SecureTrustManagerFactory.DataCertificateException cause) {
    Log.e(TAG, "Invalid certificate of account " + jaxmpp.getSessionObject().getUserBareJid() + ": "
            + cause.getMessage());//from  w  w w .  j a  va2s .  c om
    jaxmpp.getSessionObject().setUserProperty("CC:DISABLED", true);

    String title = getString(R.string.notification_certificate_error_title,
            jaxmpp.getSessionObject().getUserBareJid().toString());
    String text = getString(R.string.notification_certificate_error_text);

    Intent resultIntent = new Intent(this, LoginActivity.class);
    resultIntent.putExtra("account_name", jaxmpp.getSessionObject().getUserBareJid().toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(android.R.drawable.stat_notify_error).setWhen(System.currentTimeMillis())
            .setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xffff0000, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("error:" + jaxmpp.getSessionObject().getUserBareJid().toString()).hashCode(),
            builder.build());
}