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:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java

/**
 * method handles the Live card notifications
 * //from  w ww.j a v  a2 s .  c o m
 * @param context
 * @param jsonArray
 * 
 *            whenever the user is in background and new message is received
 *            a live card is created and if already present the values are
 *            updated with the current message contents.
 */
private void publishCard(final Context context, final JSONArray jsonArray) {

    if (mLiveCard == null) {
        mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
    }
    livecardView = new RemoteViews(context.getPackageName(), R.layout.activity_second);
    try {
        if (jsonArray.length() > 1) {
            String imageName1 = jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE).toLowerCase();
            imageName1 = imageName1.replace(" ", "_");
            String imageName2 = jsonArray.getJSONObject(1).getString(Constants.TAG_CASETITLE).toLowerCase();
            imageName2 = imageName2.replace(" ", "_");
            livecardView.setTextViewText(R.id.text,
                    jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE));
            livecardView.setTextViewText(R.id.livecard_ticketNo,
                    jsonArray.getJSONObject(0).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)");
            livecardView.setTextViewText(R.id.text2,
                    jsonArray.getJSONObject(1).getString(Constants.TAG_CASETITLE));
            livecardView.setTextViewText(R.id.livecard_ticketNo2,
                    jsonArray.getJSONObject(1).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)");
            try {
                String fnm = imageName1; // this is image
                // file name
                final String image2 = imageName2;
                String packageName = getApplicationContext().getPackageName();
                final int imgId = getResources().getIdentifier(packageName + ":drawable/" + fnm, null, null);
                final int imgId2 = getResources().getIdentifier(packageName + ":drawable/" + image2, null,
                        null);
                livecardView.setImageViewBitmap(R.id.image1_livecard,
                        BitmapFactory.decodeResource(getResources(), imgId));
                livecardView.setImageViewBitmap(R.id.image2_livecard,
                        BitmapFactory.decodeResource(getResources(), imgId2));
            } catch (Exception e) {
                e.printStackTrace();
            }
            mLiveCard.setViews(livecardView);

        } else {
            livecardView.setTextViewText(R.id.text,
                    jsonArray.getJSONObject(0).getString(Constants.TAG_CASETITLE));
            livecardView.setTextViewText(R.id.livecard_ticketNo,
                    jsonArray.getJSONObject(0).getString(Constants.TAG_TICKETCOUNT) + " ticket(s)");
            livecardView.setTextViewText(R.id.text2, "");
            livecardView.setTextViewText(R.id.livecard_ticketNo2, "");
            mLiveCard.setViews(livecardView);

        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // pending intent so that when user clicks the live card the
    // corresponding application is opened.
    Intent intent = new Intent(context, MainLauncherActivity.class);
    mLiveCard.setAction(PendingIntent.getActivity(context, 0, intent, 0));
    if (!mLiveCard.isPublished()) {
        mLiveCard.publish(LiveCard.PublishMode.SILENT);
    } else {
        mLiveCard.setViews(livecardView);
    }
}

From source file:amigoinn.example.v4sales.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();/*  w ww.  j  av a2s .co m*/
        notifyObservers(AUTOUPDATE_HAVE_UPDATE);

        // raise the notification
        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);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(appIcon);
        builder.setTicker(appName + " update");
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setContentIntent(contentIntent);
        builder.setWhen(System.currentTimeMillis());
        builder.setAutoCancel(true);
        builder.setOngoing(true);

        nm.notify(NOTIFICATION_ID, builder.build());
    } else {
        //nm.cancel( NOTIFICATION_ID );   // tried this, but it just doesn't do the trick =(
        nm.cancelAll();
    }
}

From source file:com.google.appinventor.components.runtime.ProbeBase.java

@SimpleFunction(description = "Create a notication with message to wake up "
        + "another activity when tap on the notification")
public void CreateNotification(String title, String text, boolean enabledSound, boolean enabledVibrate,
        String packageName, String className, String extraKey, String extraVal) throws ClassNotFoundException {

    Intent activityToLaunch = new Intent(Intent.ACTION_MAIN);

    Log.i(TAG, "packageName: " + packageName);
    Log.i(TAG, "className: " + className);

    // for local AI instance, all classes are under the package
    // "appinventor.ai_test"
    // but for those runs on Google AppSpot(AppEngine), the package name will be
    // "appinventor.ai_GoogleAccountUserName"
    // e.g. pakageName = appinventor.ai_HomerSimpson.HelloPurr
    // && className = appinventor.ai_HomerSimpson.HelloPurr.Screen1

    ComponentName component = new ComponentName(packageName, className);
    activityToLaunch.setComponent(component);
    activityToLaunch.putExtra(extraKey, extraVal);

    Log.i(TAG, "we found the class for intent to send into notificaiton");

    activityToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    mContentIntent = PendingIntent.getActivity(mainUIThreadActivity, 0, activityToLaunch, 0);

    Long currentTimeMillis = System.currentTimeMillis();
    notification = new Notification(R.drawable.stat_notify_chat, "Activate Notification!", currentTimeMillis);

    Log.i(TAG, "After creating notification");
    notification.contentIntent = mContentIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // reset the notification
    notification.defaults = 0;//from w ww  . java 2s .  co m

    if (enabledSound)
        notification.defaults |= Notification.DEFAULT_SOUND;

    if (enabledVibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.setLatestEventInfo(mainUIThreadActivity, (CharSequence) title, (CharSequence) text,
            mContentIntent);
    Log.i(TAG, "after updated notification contents");
    mNM.notify(PROBE_NOTIFICATION_ID, notification);
    Log.i(TAG, "notified");

}

From source file:com.horizondigital.delta.UpdateService.java

private PendingIntent getNotificationIntent(boolean delete) {
    if (delete) {
        Intent notificationIntent = new Intent(this, UpdateService.class);
        notificationIntent.setAction(ACTION_NOTIFICATION_DELETED);
        return PendingIntent.getService(this, 0, notificationIntent, 0);
    } else {//from   ww  w .  j  a  v  a  2s  . com
        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(ACTION_SYSTEM_UPDATE_SETTINGS);
        return PendingIntent.getActivity(this, 0, notificationIntent, 0);
    }
}

From source file:com.wojtechnology.sunami.TheBrain.java

private Notification.Builder getLollipopNotifBuilder(boolean isPlaying) {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 1, notificationIntent, 0);

    Intent serviceLastIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceLastIntent.setAction(TheBrain.PLAY_LAST);
    serviceLastIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingLastIntent = PendingIntent.getService(mContext, 1, serviceLastIntent, 0);
    Intent servicePlayIntent = new Intent(getApplicationContext(), TheBrain.class);
    servicePlayIntent.setAction(TheBrain.TOGGLE_PLAY);
    servicePlayIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingPlayIntent = PendingIntent.getService(mContext, 1, servicePlayIntent, 0);
    Intent serviceNextIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceNextIntent.setAction(TheBrain.PLAY_NEXT);
    serviceNextIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingNextIntent = PendingIntent.getService(mContext, 1, serviceNextIntent, 0);
    Intent serviceStopIntent = new Intent(getApplicationContext(), TheBrain.class);
    serviceStopIntent.setAction(TheBrain.PLAY_STOP);
    serviceStopIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    PendingIntent pendingStopIntent = PendingIntent.getService(mContext, 1, serviceStopIntent, 0);

    Notification.MediaStyle style = new Notification.MediaStyle();
    style.setShowActionsInCompactView(1, 2);
    Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.mipmap.sunaminotif)
            .setContentIntent(pendingIntent).setStyle(style);
    builder.addAction(R.drawable.ic_last_hint, "Last", pendingLastIntent);
    builder.addAction(isPlaying ? R.drawable.ic_pause_hint : R.drawable.ic_play_hint, "Play",
            pendingPlayIntent);/* www.j a  va2 s . co  m*/
    builder.addAction(R.drawable.ic_next_hint, "Next", pendingNextIntent);
    builder.addAction(R.drawable.ic_stop_notif, "Stop", pendingStopIntent);
    return builder;
}

From source file:org.kaoriha.phonegap.plugins.releasenotification.Notifier.java

private void pollBackground() {
    if (getToken() == null) {
        rescheduleAfterFail();/*  w  ww.  ja v a 2  s .c om*/
        return;
    }

    ToNextReleasePolling tp = new ToNextReleasePolling();
    tp.poll();
    if (tp.isFailed) {
        Log.d(TAG, "ToNextReleasePolling failed");
        rescheduleAfterFail();
        return;
    }

    CataloguePolling cp = new CataloguePolling();
    cp.poll();
    if (cp.isFailed) {
        Log.d(TAG, "CataloguePolling failed");
        rescheduleAfterFail();
        return;
    }
    if (!cp.isNew) {
        if (tp.toNextRelease == -1) {
            schedule(RESCHEDULE_NEXT_UNKNOWN_SPAN);
        } else {
            schedule(tp.toNextRelease);
        }
        Log.d(TAG, "CataloguePolling not new");
        return;
    }

    String pushMessage;
    if (cp.catalogue.has(CATALOGUE_PUSH_MESSAGE_KEY)) {
        try {
            pushMessage = cp.catalogue.getString(CATALOGUE_PUSH_MESSAGE_KEY);
        } catch (JSONException e) {
            Log.i(TAG, "pollBackground()", e);
            pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
        }
    } else {
        pushMessage = pref.getString(SPKEY_DEFAULT_PUSH_MESSAGE, null);
    }

    String lastSid;
    try {
        lastSid = getLastSid(cp.catalogue);
        if (lastSid.equals(pref.getString(SPKEY_LAST_SID, null))) {
            schedule(tp.toNextRelease);
        }
    } catch (JSONException e) {
        Log.d(TAG, "bad JSON", e);
        rescheduleAfterFail();
        return;
    }

    int icon = R.drawable.notification;
    Notification n = new Notification(icon, pushMessage, System.currentTimeMillis());
    n.flags = Notification.FLAG_AUTO_CANCEL;
    Intent i = new Intent(ctx, FlowerflowerActivity.class);
    i.setAction(Intent.ACTION_MAIN);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(ctx, 0, i, 0);
    n.setLatestEventInfo(ctx.getApplicationContext(), pref.getString(SPKEY_TITLE, null), pushMessage, pi);
    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, n);

    pref.edit().putString(SPKEY_LAST_SID, lastSid).putString(SPKEY_LAST_CATALOGUE_ETAG, cp.etag).commit();

    clearFailRepeat();

    schedule(tp.toNextRelease);

    Log.d(TAG, "pollBackground() success");
}

From source file:me.willowcheng.makerthings.ui.OpenHABMainActivity.java

@Override
public void onResume() {
    Log.d(TAG, "onResume()");
    super.onResume();
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, ((Object) this).getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    if (NfcAdapter.getDefaultAdapter(this) != null)
        NfcAdapter.getDefaultAdapter(this).enableForegroundDispatch(this, pendingIntent, null, null);
    if (!TextUtils.isEmpty(mNfcData)) {
        Log.d(TAG, "We have NFC data from launch");
    }/*from   w  w  w . j av  a  2  s.c o  m*/
    pagerAdapter.setColumnsNumber(getResources().getInteger(R.integer.pager_columns));
    FragmentManager fm = getSupportFragmentManager();
    stateFragment = (StateRetainFragment) fm.findFragmentByTag("stateFragment");
    // If state fragment doesn't exist (which means fresh start of the app)
    // or if state fragment returned 0 fragments (this happens sometimes and we don't yet
    // know why, so this is a workaround
    // start over the whole process
    if (stateFragment == null || stateFragment.getFragmentList().size() == 0) {
        stateFragment = null;
        stateFragment = new StateRetainFragment();
        fm.beginTransaction().add(stateFragment, "stateFragment").commit();
        mOpenHABTracker = new OpenHABTracker(this, openHABServiceType, mServiceDiscoveryEnabled);
        mStartedWithNetworkConnectivityInfo = NetworkConnectivityInfo.currentNetworkConnectivityInfo(this);
        mOpenHABTracker.start();
        // If state fragment exists and contains something then just restore the fragments
    } else {
        Log.d(TAG, "State fragment found");
        // If connectivity type changed while we were in background
        // Restart the whole process
        // TODO: this must be refactored to remove duplicate code!
        if (!NetworkConnectivityInfo.currentNetworkConnectivityInfo(this)
                .equals(mStartedWithNetworkConnectivityInfo)) {
            Log.d(TAG, "Connectivity type changed while I was out, or zero fragments found, need to restart");
            // Clean up any existing fragments
            pagerAdapter.clearFragmentList();
            stateFragment.getFragmentList().clear();
            stateFragment = null;
            // Clean up title
            this.setTitle(R.string.app_name);
            stateFragment = new StateRetainFragment();
            fm.beginTransaction().add(stateFragment, "stateFragment").commit();
            mOpenHABTracker = new OpenHABTracker(this, openHABServiceType, mServiceDiscoveryEnabled);
            mStartedWithNetworkConnectivityInfo = NetworkConnectivityInfo.currentNetworkConnectivityInfo(this);
            mOpenHABTracker.start();
            return;
        }
        pagerAdapter.setFragmentList(stateFragment.getFragmentList());
        Log.d(TAG, String.format("Loaded %d fragments", stateFragment.getFragmentList().size()));
        pager.setCurrentItem(stateFragment.getCurrentPage());
        Log.d(TAG, String.format("Loaded current page = %d", stateFragment.getCurrentPage()));
    }
    if (!TextUtils.isEmpty(mPendingNfcPage)) {
        openNFCPageIfPending();
    }

    checkFullscreen();
}

From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java

/**
 * Updates the notification./*  w ww. j a  v  a 2s  . co m*/
 */
void updateNotification(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), Urgent.class), PendingIntent.FLAG_UPDATE_CURRENT);
    mNotification.setLatestEventInfo(getApplicationContext(), "Urgent.fm", text, pi);
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
}

From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java

/**
 * Configures service as a foreground service. A foreground service is a service that's doing
 * something the user is actively aware of (such as playing music), and must appear to the user
 * as a notification. That's why we create the notification here.
 *//*w  w w . j ava2s. c  om*/
void setUpAsForeground(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), Urgent.class), PendingIntent.FLAG_UPDATE_CURRENT);

    mNotification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.urgent_icon)
            .setTicker(text).setContentTitle("Urgent.fm livestream").setContentText(text).setContentIntent(pi)
            .build();

    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, mNotification);
}