Example usage for android.app Notification setLatestEventInfo

List of usage examples for android.app Notification setLatestEventInfo

Introduction

In this page you can find the example usage for android.app Notification setLatestEventInfo.

Prototype

@Deprecated
public void setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText,
        PendingIntent contentIntent) 

Source Link

Document

Sets the #contentView field to be a view with the standard "Latest Event" layout.

Usage

From source file:net.helff.wificonnector.WifiConnectivityService.java

protected void sendNotification(String msg) {
    Log.i(TAG, "send notification: " + msg);
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Notification notification = new Notification(R.drawable.launchericon, msg, System.currentTimeMillis());

    Intent intent = new Intent(this, WifiConnectorActivity.class);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    notification.setLatestEventInfo(this.getApplicationContext(), "WifiConnector", msg, pendingIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(1, notification);

}

From source file:com.fordemobile.livepaintings.FragmentPagerSupport.java

public void notifyUser(int titleId, int messageId) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.icon;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, getString(titleId), when);

    Context context = getApplicationContext();
    CharSequence contentTitle = getString(titleId);
    CharSequence contentText = getString(messageId);
    Intent notificationIntent = new Intent(this, FragmentPagerSupport.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    mNotificationManager.notify(0, notification);
}

From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java

private Notification createLegacyNotification(final int iconResId, final String title, final String contentText,
        final PendingIntent contentIntent) {
    final Notification notification = new Notification();
    notification.icon = iconResId;/*ww  w. j a v a 2s  .c o m*/
    notification.setLatestEventInfo(this.pinpointContext.getApplicationContext(), title, contentText,
            contentIntent);
    notification.contentIntent = contentIntent;
    return notification;
}

From source file:uk.ac.horizon.ubihelper.service.LogManager.java

private void signalError(String error) {
    // force re-check...
    currentLogDir = null;// w w w.  j a  va 2 s  .co  m
    if (errorNotificationVisible && error.equals(errorNotificationText))
        return;
    errorNotificationText = error;

    int icon = R.drawable.log_error_notification_icon;
    CharSequence tickerText = error;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);

    Context context = service;
    CharSequence contentTitle = "Ubihelper Logging";
    CharSequence contentText = error;
    Intent notificationIntent = new Intent(LoggingPreferences.INTENT);
    PendingIntent contentIntent = PendingIntent.getActivity(service, 0, notificationIntent, 0);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
    NotificationManager mNotificationManager = (NotificationManager) service
            .getSystemService(Service.NOTIFICATION_SERVICE);
    //service.(ci.notificationId, notification);   
    mNotificationManager.notify(ERROR_NOTIFICATION_ID, notification);
    errorNotificationVisible = true;
}

From source file:com.github.vseguip.sweet.contacts.SweetContactSync.java

@Override
public void onPerformSync(final Account account, Bundle extras, String authority,
        ContentProviderClient provider, SyncResult syncResult) {
    Log.i(TAG, "onPerformSync()");
    // Get preferences
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean fullSync = settings.getBoolean(mContext.getString(R.string.full_sync), false);
    if (fullSync)
        mAccountManager.setUserData(account, LAST_SYNC_KEY, null);
    performNetOperation(new SugarRunnable(account, syncResult, new ISugarRunnable() {
        @Override/*from w ww  .jav a2  s .  c  om*/
        public void run() throws URISyntaxException, OperationCanceledException, AuthenticatorException,
                IOException, AuthenticationException {
            Log.i(TAG, "Running PerformSync closure()");

            mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, true);
            SugarAPI sugar = SugarAPIFactory.getSugarAPI(mAccountManager, account);
            String lastDate = mAccountManager.getUserData(account, LAST_SYNC_KEY);
            List<ISweetContact> contacts = null;
            try {
                contacts = fetchContacts(sugar, lastDate);
            } catch (AuthenticationException ex) {
                // maybe expired session, invalidate token and request new
                // one
                mAccountManager.invalidateAuthToken(account.type, mAuthToken);
                mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, false);
            } catch (NullPointerException npe) {
                // maybe expired session, invalidate token and request new
                // one               
                mAccountManager.invalidateAuthToken(account.type, mAuthToken);
                mAuthToken = mAccountManager.blockingGetAuthToken(account, AUTH_TOKEN_TYPE, false);
            }
            // try again, it could be due to an expired session
            if (contacts == null) {
                contacts = fetchContacts(sugar, lastDate);
            }
            List<ISweetContact> modifiedContacts = ContactManager.getLocallyModifiedContacts(mContext, account);
            List<ISweetContact> createdContacts = ContactManager.getLocallyCreatedContacts(mContext, account);
            // Get latest date from server
            for (ISweetContact c : contacts) {
                String contactDate = c.getDateModified();
                if ((lastDate == null) || (lastDate.compareTo(contactDate) < 0)) {
                    lastDate = contactDate;
                }
            }
            // Determine conflicting contacts
            Set<String> conflictSet = getConflictSet(contacts, modifiedContacts);
            Map<String, ISweetContact> conflictingSugarContacts = filterIds(contacts, conflictSet);
            Map<String, ISweetContact> conflictingLocalContacts = filterIds(modifiedContacts, conflictSet);

            if (modifiedContacts.size() > 0) {
                // Send modified local non conflicting contacts to the
                // server
                List<String> newIds = sugar.sendNewContacts(mAuthToken, modifiedContacts, false);
                if (newIds.size() != modifiedContacts.size()) {
                    throw new OperationCanceledException("Error updating local contacts in the remote server");
                }
                ContactManager.cleanDirtyFlag(mContext, modifiedContacts);
            }
            if (createdContacts.size() > 0) {
                List<String> newIds = sugar.sendNewContacts(mAuthToken, createdContacts, true);
                if (newIds.size() != createdContacts.size()) {
                    // something wrong happened, it's probable the user will
                    // have to clear the data
                    throw new OperationCanceledException("Error creating local contacts in the remote server");
                }
                ContactManager.assignSourceIds(mContext, createdContacts, newIds);
                ContactManager.cleanDirtyFlag(mContext, createdContacts);
            }
            // Sync remote contacts locally.
            if (contacts.size() > 0) {
                ContactManager.syncContacts(mContext, account, contacts);
            }
            // resolve remaining conflicts
            List<ISweetContact> resolvedContacts = new ArrayList<ISweetContact>();
            for (String id : conflictSet) {
                ISweetContact local = conflictingLocalContacts.get(id);
                ISweetContact remote = conflictingSugarContacts.get(id);
                if (local.equals(remote)) {
                    // no need to sync
                    resolvedContacts.add(local);
                    conflictingLocalContacts.remove(id);
                    conflictingSugarContacts.remove(id);
                } else {
                    Log.i(TAG, "Local contact differs from remote contact " + local.getFirstName() + " "
                            + local.getLastName());
                    if (local.equalUIFields(remote)) {
                        // Differed in a non visible field like the account
                        // id or similar, use server version and resolve
                        // automatically
                        resolvedContacts.add(remote);
                        conflictingLocalContacts.remove(id);
                        conflictingSugarContacts.remove(id);
                    }
                }

            }
            ContactManager.cleanDirtyFlag(mContext, resolvedContacts);
            if (conflictingLocalContacts.size() > 0) {
                // Create a notification that can launch an mActivity to
                // resolve the pending conflict
                NotificationManager nm = (NotificationManager) mContext
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                Notification notify = new Notification(R.drawable.icon,
                        mContext.getString(R.string.notify_sync_conflict_ticket), System.currentTimeMillis());
                Intent intent = new Intent(mContext, SweetConflictResolveActivity.class);
                intent.putExtra("account", account);
                SweetConflictResolveActivity.storeConflicts(conflictingLocalContacts, conflictingSugarContacts);

                notify.setLatestEventInfo(mContext, mContext.getString(R.string.notify_sync_conflict_title),
                        mContext.getString(R.string.notify_sync_conflict_message),
                        PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
                nm.notify(SweetConflictResolveActivity.NOTIFY_CONFLICT,
                        SweetConflictResolveActivity.NOTIFY_CONTACT, notify);

                throw new OperationCanceledException("Pending conflicts");
            }
            // Save the last sync time in the account if all went ok
            mAccountManager.setUserData(account, LAST_SYNC_KEY, lastDate);
        }
    }));
}

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

private void pollBackground() {
    if (getToken() == null) {
        rescheduleAfterFail();//from   w w  w. ja v  a2  s. c  o m
        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:com.googlecode.android_scripting.facade.AndroidFacade.java

@Rpc(description = "Displays a notification that will be canceled when the user clicks on it.")
public void notify(@RpcParameter(name = "title", description = "title") String title,
        @RpcParameter(name = "message") String message) {
    Notification notification = new Notification(mResources.getLogo48(), message, System.currentTimeMillis());
    // This contentIntent is a noop.
    PendingIntent contentIntent = PendingIntent.getService(mService, 0, new Intent(), 0);
    notification.setLatestEventInfo(mService, title, message, contentIntent);
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    // Get a unique notification id from the application.
    final int notificationId = NotificationIdFactory.create();
    mNotificationManager.notify(notificationId, notification);
}

From source file:com.akop.bach.service.XboxLiveServiceClient.java

private void notifyFriends(XboxLiveAccount account, long[] friendsOnline, List<Long> lastFriendsOnline) {
    NotificationManager mgr = getNotificationManager();
    Context context = getContext();

    int notificationId = 0x2000000 | ((int) account.getId() & 0xffffff);

    if (App.getConfig().logToConsole()) {
        String s = "";
        for (Object unr : lastFriendsOnline)
            s += unr.toString() + ",";

        App.logv("Currently online (%d): %s", lastFriendsOnline.size(), s);

        s = "";//from  w w  w .j a v a 2s  .c o  m
        for (Object unr : friendsOnline)
            s += unr.toString() + ",";

        App.logv("New online (%d): %s", friendsOnline.length, s);
    }

    if (friendsOnline.length > 0) {
        int newOnlineCount = 0;
        for (Object online : friendsOnline)
            if (!lastFriendsOnline.contains(online))
                newOnlineCount++;

        if (App.getConfig().logToConsole())
            App.logv("%d computed new; %d online now; %d online before", newOnlineCount, friendsOnline.length,
                    lastFriendsOnline.size());

        if (newOnlineCount > 0) {
            // Prepare notification objects
            String tickerTitle;
            String tickerText;

            if (friendsOnline.length == 1) {
                tickerTitle = context.getString(R.string.friend_online);
                tickerText = context.getString(R.string.notify_friend_online_f,
                        Friends.getGamertag(context, friendsOnline[0]), account.getDescription());
            } else {
                tickerTitle = context.getString(R.string.friends_online);
                tickerText = context.getString(R.string.notify_friends_online_f, account.getScreenName(),
                        friendsOnline.length, account.getDescription());
            }

            Notification notification = new Notification(R.drawable.xbox_stat_notify_friend, tickerText,
                    System.currentTimeMillis());
            notification.flags |= Notification.FLAG_AUTO_CANCEL;

            Intent intent = new Intent(context, FriendList.class);
            intent.putExtra("account", account);

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);

            notification.setLatestEventInfo(context, tickerTitle, tickerText, contentIntent);

            // New users online

            if (friendsOnline.length > 1)
                notification.number = friendsOnline.length;

            notification.flags |= Notification.FLAG_SHOW_LIGHTS;
            notification.ledOnMS = DEFAULT_LIGHTS_ON_MS;
            notification.ledOffMS = DEFAULT_LIGHTS_OFF_MS;
            notification.ledARGB = DEFAULT_LIGHTS_COLOR;
            notification.sound = account.getRingtoneUri();

            if (account.isVibrationEnabled())
                notification.defaults |= Notification.DEFAULT_VIBRATE;

            mgr.notify(notificationId, notification);
        }
    } else // No unread messages
    {
        mgr.cancel(notificationId);
    }
}

From source file:name.setup.dance.StepService.java

/**
 * Show a notification while this service is running.
 *//* w w  w  .j a v  a2  s . c  o m*/
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent DanceStepAppIntent = new Intent();
    DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class));
    DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:com.inloc.dr.StepService.java

/**
 * Show a notification while this service is running.
 *///from   w  w  w  .  ja  v  a  2  s . com
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent pedometerIntent = new Intent();
    pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class));
    pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}