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: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 ww w .  j a v a  2 s .  com
}

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());/*w  w  w  . j  a v  a2 s .  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());
}

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

private void processSubscriptionRequest(final SessionObject sessionObject, final Presence stanza,
        final BareJID jid) {
    Log.e(TAG, "Subscription request from  " + jid);

    retrieveVCard(sessionObject, jid);//ww  w .j a v a2 s.co m

    String title = getString(R.string.notification_subscription_request_title, jid.toString());
    String text = getString(R.string.notification_subscription_request_text);

    Intent resultIntent = new Intent(this, SubscriptionRequestActivity.class);
    resultIntent.putExtra("account_name", sessionObject.getUserBareJid().toString());
    resultIntent.putExtra("jid", jid.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(R.drawable.ic_messenger_icon).setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

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

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

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("request:" + sessionObject.getUserBareJid().toString() + ":" + jid).hashCode(),
            builder.build());
}

From source file:net.wespot.pim.view.InqCommunicateFragment.java

private void createNotification(MessageLocalObject messageLocalObject, Long runId) {

    if (!runIdList.contains(runId)) {
        runIdList.add(runId);//  w  ww  .  j a va 2  s.c o m
        runIdList_str.add(runId.toString());
    }

    numMessages = 0;
    mBuilder = null;
    mNotificationStyle = null;
    mNotificationManager = null;

    mNotificationManager = (NotificationManager) ARL.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationStyle = new NotificationCompat.InboxStyle();
    mBuilder = new NotificationCompat.Builder(ARL.getContext()).setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(true).setSortKey("0")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setStyle(mNotificationStyle);

    InquiryLocalObject inquiryLocalObject = DaoConfiguration.getInstance().getInquiryLocalObjectDao()
            .queryBuilder().where(InquiryLocalObjectDao.Properties.RunId.eq(runId)).list().get(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
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ARL.getContext());

    Intent resultIntent;

    if (runIdList.size() > 1) {
        resultIntent = new Intent(ARL.getContext(), PimInquiriesFragment.class);
        resultIntent.putStringArrayListExtra(INQUIRIES_ID, (ArrayList<String>) runIdList_str);

        Intent parent = new Intent(ARL.getContext(), MainActivity.class);
        Intent parent1 = new Intent(ARL.getContext(), SplashActivity.class);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addNextIntentWithParentStack(parent1);
        stackBuilder.addNextIntentWithParentStack(parent);

    } else {
        resultIntent = new Intent(ARL.getContext(), InquiryPhasesActivity.class);
        resultIntent.putExtra(INQUIRY_ID, inquiryLocalObject.getId());

        Intent parent = new Intent(ARL.getContext(), PimInquiriesFragment.class);
        Intent parent1 = new Intent(ARL.getContext(), MainActivity.class);
        Intent parent2 = new Intent(ARL.getContext(), SplashActivity.class);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addNextIntentWithParentStack(parent2);
        stackBuilder.addNextIntentWithParentStack(parent1);
        stackBuilder.addNextIntentWithParentStack(parent);
    }

    // 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 (runIdList.size() == 1) {
        // More than 1 inquiries have messages

        mBuilder.setContentTitle(inquiryLocalObject.getTitle());
        for (MessageLocalObject me : notications_queue_messages) {
            mNotificationStyle.addLine(getNameUser(me.getAuthor()) + ": " + me.getBody()).setSummaryText(
                    ++numMessages != 1 ? numMessages + " new messages" : numMessages + " new message");
        }
    }

    if (runIdList.size() > 1) {
        // More than 1 inquiries have messages

        for (MessageLocalObject me : notications_queue_messages) {
            mBuilder.setContentTitle("Personal Inquiry Manager");
            InquiryLocalObject a = DaoConfiguration.getInstance().getInquiryLocalObjectDao().queryBuilder()
                    .where(InquiryLocalObjectDao.Properties.RunId.eq(me.getRunId())).list().get(0);

            mNotificationStyle.addLine(getNameUser(me.getAuthor()) + " @ " + a.getTitle() + ": " + me.getBody())
                    .setSummaryText(++numMessages != 1
                            ? numMessages + " new messages from " + runIdList.size() + " conversations" + " "
                            : numMessages + " new message from " + runIdList.size() + " conversations");
        }
    }

    mNotificationManager.notify(Integer.parseInt(NUMBER), mBuilder.build());
}