Example usage for android.app PendingIntent getActivity

List of usage examples for android.app PendingIntent getActivity

Introduction

In this page you can find the example usage for android.app PendingIntent getActivity.

Prototype

public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags) 

Source Link

Document

Retrieve a PendingIntent that will start a new activity, like calling Context#startActivity(Intent) Context.startActivity(Intent) .

Usage

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

private void setupForegroundDispatch() {
    /* initialize the PendingIntent to start for the dispatch */
    nfcPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    /* initialize the IntentFilters to override dispatching for */
    nfcIntentFilters = new IntentFilter[3];
    nfcIntentFilters[0] = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    nfcIntentFilters[0].addCategory(Intent.CATEGORY_DEFAULT);
    nfcIntentFilters[1] = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    nfcIntentFilters[1].addCategory(Intent.CATEGORY_DEFAULT);
    nfcIntentFilters[2] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    nfcIntentFilters[2].addCategory(Intent.CATEGORY_DEFAULT);
    try {// www  . j av  a2s.  co m
        nfcIntentFilters[0].addDataType("*/*"); // Handle all MIME based dispatches.
    } catch (IntentFilter.MalformedMimeTypeException e) {
        Log.e(TAG, "setupForegroundDispatch: " + e.getMessage());
    }

    /* Initialize the tech lists used to perform matching for dispatching of the
     * ACTION_TECH_DISCOVERED intent */
    nfcTechLists = new String[][] {};
}

From source file:at.alladin.rmbt.android.test.RMBTLoopService.java

private NotificationCompat.Builder createNotificationBuilder() {
    final Resources res = getResources();

    Intent notificationIntent = new Intent(getApplicationContext(), RMBTMainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent openAppIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_icon_loop)
            .setContentTitle(res.getText(R.string.loop_notification_title))
            .setTicker(res.getText(R.string.loop_notification_ticker)).setContentIntent(openAppIntent);

    setNotificationText(builder);/*from  ww w  .j a  va  2  s  .  co  m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (SHOW_DEV_BUTTONS) {
            final Intent stopIntent = new Intent(ACTION_STOP, null, getApplicationContext(), getClass());
            final PendingIntent stopPIntent = PendingIntent.getService(getApplicationContext(), 0, stopIntent,
                    0);
            final Intent forceIntent = new Intent(ACTION_FORCE, null, getApplicationContext(), getClass());
            final PendingIntent forcePIntent = PendingIntent.getService(getApplicationContext(), 0, forceIntent,
                    0);

            addActionToNotificationBuilder(builder, stopPIntent, forcePIntent);
        }
    }

    return builder;
}

From source file:io.coldstart.android.GCMIntentService.java

private void SendCombinedNotification(String EventCount) {
    Notification notification = new Notification(R.drawable.ic_stat_alert, EventCount + " new SNMP Traps!",
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    notification.ledARGB = 0xffff0000;/*from w  w  w  .  jav  a2 s.  co  m*/

    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;

    notification.defaults |= Notification.DEFAULT_SOUND;

    Context context = getApplicationContext();
    Intent notificationIntent = new Intent(this, TrapListActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("forceRefresh", true);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, EventCount + " SNMP Traps", "Click to launch ColdStart.io",
            contentIntent);
    mNM.notify(43523, notification);//NotificationID++ 
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static void notifyUser(final String msg, final int pct) {
    Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    if (mNotifyBuilder == null) {
        mNotifyBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
                .setContentTitle(context.getString(R.string.app_name))
                .setContentText(context.getString(R.string.flowzr_sync_inprogress))
                .setSmallIcon(R.drawable.icon);

        mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // Sets an ID for the notification, so it can be updated
    }//  w  w  w.  j  a  v  a2 s .  c o  m
    mNotifyBuilder.setContentText(msg);
    mNotifyBuilder.setContentIntent(pendingIntent);
    mNotifyBuilder.setAutoCancel(true).build();
    if (pct != 0) {
        mNotifyBuilder.setProgress(100, pct, false);
    }
    mNotificationManager.notify(NOTIFICATION_ID, mNotifyBuilder.build());
}

From source file:com.dafeng.upgradeapp.util.AutoUpdateApk.java

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        setChanged();/*from ww  w  .j a v a 2  s  . c  o m*/
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:com.chasetech.pcount.autoupdate.AutoUpdateApk.java

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");

    if (update_file.length() > 0) {
        setChanged();/*from w  w w .j av  a  2 s  . c o m*/
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise notification
        //            Notification notification = new Notification(
        //                    appIcon, appName + " update", System.currentTimeMillis());
        //            notification.flags |= NOTIFICATION_FLAGS;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Click this to install..";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        Notification.Builder builder = new Notification.Builder(context);

        builder.setAutoCancel(false);
        builder.setTicker("An update is available.");
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setSmallIcon(appIcon);
        builder.setContentIntent(contentIntent);
        builder.setOngoing(true);
        builder.setSubText(appName + " update"); //API level 16
        builder.setNumber(100);
        builder.build();

        Notification myNotication = builder.getNotification();
        nm.notify(NOTIFICATION_ID, myNotication);

        //            notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        //            nm.notify( NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }

    //      if( update_file.length() > 0 ) {
    //         setChanged();
    //         notifyObservers(AUTOUPDATE_HAVE_UPDATE);
    //
    //         // raise notification
    ///*         Notification notification = new Notification(
    //               appIcon, appName + " update", System.currentTimeMillis());*/
    //            Notification.Builder notifBuilder = new Notification.Builder(context);
    //         //notification.flags |= NOTIFICATION_FLAGS;
    //
    //         CharSequence contentTitle = appName + " update available";
    //         CharSequence contentText = "Select to install";
    //         Intent notificationIntent = new Intent(Intent.ACTION_VIEW );
    //         Uri uriFile = Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file);
    //         notificationIntent.setDataAndType(uriFile, ANDROID_PACKAGE);
    //         PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    //
    //            notifBuilder.setContentTitle(contentTitle);
    //            notifBuilder.setContentText(contentText);
    //            notifBuilder.setContentIntent(contentIntent);
    //            notifBuilder.setSubText("Update available.");
    //            notifBuilder.build();
    //
    //            Notification notification = notifBuilder.build();
    //            notification.flags |= NOTIFICATION_FLAGS;
    //
    //            nm.notify(NOTIFICATION_ID, notification);
    //
    //         //notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    //         //nm.notify( NOTIFICATION_ID, notification);
    //      } else {
    //         nm.cancel( NOTIFICATION_ID );
    //      }
}

From source file:com.ecocitizen.service.SensorMapUploaderService.java

private void updateStatus(Status status) {
    if (this.status == status)
        return;// ww w  . j a  v a 2s  .  c  o m
    this.status = status;

    Context context = getApplicationContext();
    CharSequence contentTitle = context.getString(com.ecocitizen.app.R.string.notification_smu_title);
    CharSequence tickerText = context.getString(com.ecocitizen.app.R.string.notification_smu_ticker);

    Notification notification;
    long when = System.currentTimeMillis();
    int icon = 0;
    CharSequence contentText = null;

    switch (status) {
    case LOGINERROR:
        icon = ICON_LOGINERROR;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_loginerror);
        break;
    case STANDBY:
        icon = ICON_STANDBY;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_standby);
        break;
    case UPLOADING:
        icon = ICON_UPLOADING;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_uploading);
        break;
    case BLOCKED:
    default:
        icon = ICON_BLOCKED;
        contentText = context.getString(com.ecocitizen.app.R.string.notification_smu_blocked);
        break;
    }
    notification = new Notification(icon, tickerText, when);
    Intent notificationIntent = new Intent(this, TreeViewActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(1, notification);
}

From source file:arun.com.chromer.browsing.customtabs.CustomTabs.java

private void prepareChromerOptions() {
    final Intent moreMenuActivity = new Intent(activity, ChromerOptionsActivity.class);
    moreMenuActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    moreMenuActivity.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        moreMenuActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    }/*from  ww  w .  j  av a  2  s.  com*/
    moreMenuActivity.putExtra(EXTRA_KEY_ORIGINAL_URL, url);
    final PendingIntent moreMenuPending = PendingIntent.getActivity(activity, 0, moreMenuActivity,
            FLAG_UPDATE_CURRENT);
    builder.addMenuItem(activity.getString(R.string.chromer_options), moreMenuPending);
}

From source file:org.ohmage.sync.OhmageSyncAdapter.java

private void showInstallApkNotification(int id, Builder builder, Intent intent) {
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getContext(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent).setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);

    NotificationManager mNotificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(id, builder.build());
}

From source file:com.facebook.notifications.NotificationsManager.java

/**
 * Present a {@link Notification} to be presented from a GCM push bundle.
 * <p/>//from w w  w  .  jav  a  2 s.  co m
 * This does not present a notification immediately, instead it caches the assets from the
 * notification bundle, and then presents a notification to the user. This allows for a smoother
 * interaction without loading indicators for the user.
 * <p/>
 * Note that only one notification can be created for a specific push bundle, should you attempt
 * to present a new notification with the same payload bundle as an existing notification, it will
 * replace and update the old notification.
 *
 * @param context              The context to send the notification from
 * @param notificationBundle   The content of the push notification
 * @param launcherIntent       The launcher intent that contains your Application's activity.
 *                             This will be modified with the FLAG_ACTIVITY_CLEAR_TOP and
 *                             FLAG_ACTIVITY_SINGLE_TOP flags, in order to properly show the
 *                             notification in an already running application.
 *                             <p/>
 *                             Should you not want this behavior, you may use the notificationExtender
 *                             parameter to customize the contentIntent of the notification before
 *                             presenting it.
 * @param notificationExtender A nullable argument that allows you to customize the notification
 *                             before displaying it. Use this to configure Icons, text, sounds,
 *                             etc. before we pass the notification off to the OS.
 */
public static boolean presentNotification(@NonNull final Context context,
        @NonNull final Bundle notificationBundle, @NonNull final Intent launcherIntent,
        @Nullable final NotificationExtender notificationExtender) {
    final JSONObject alert;
    final int payloadHash;

    try {
        String payload = notificationBundle.getString(CARD_PAYLOAD_KEY);
        if (payload == null) {
            return false;
        }
        payloadHash = payload.hashCode();

        JSONObject payloadObject = new JSONObject(payload);
        alert = payloadObject.optJSONObject("alert") != null ? payloadObject.optJSONObject("alert")
                : new JSONObject();
    } catch (JSONException ex) {
        Log.e(LOG_TAG, "Error while parsing notification bundle JSON", ex);
        return false;
    }

    final boolean[] success = new boolean[1];

    final Thread backgroundThread = new Thread(new Runnable() {
        @Override
        public void run() {
            Looper.prepare();
            prepareCard(context, notificationBundle, new PrepareCallback() {
                @Override
                public void onPrepared(@NonNull Intent presentationIntent) {
                    Intent contentIntent = new Intent(launcherIntent);
                    contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    contentIntent.putExtra(EXTRA_PAYLOAD_INTENT, presentationIntent);

                    NotificationManager manager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    Notification.Builder builder = new Notification.Builder(context)
                            .setSmallIcon(android.R.drawable.ic_dialog_alert)
                            .setContentTitle(alert.optString("title")).setContentText(alert.optString("body"))
                            .setAutoCancel(true)
                            .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(),
                                    payloadHash, contentIntent, PendingIntent.FLAG_ONE_SHOT));

                    if (notificationExtender != null) {
                        builder = notificationExtender.extendNotification(builder);
                    }

                    manager.notify(NOTIFICATION_TAG, payloadHash, builder.getNotification());
                    success[0] = true;
                    Looper.myLooper().quit();
                }

                @Override
                public void onError(@NonNull Exception exception) {
                    Log.e(LOG_TAG, "Error while preparing card", exception);
                    Looper.myLooper().quit();
                }
            });

            Looper.loop();
        }
    });

    backgroundThread.start();

    try {
        backgroundThread.join();
    } catch (InterruptedException ex) {
        Log.e(LOG_TAG, "Failed to wait for background thread", ex);
        return false;
    }
    return success[0];
}