use of android.app.NotificationManager in project goro by stanfy.
the class GoroActivity method notificationSample.
private void notificationSample() {
Intent intent = GoroService.taskIntent(GoroActivity.this, QUEUE_REST, new PendingTask(counter++, QUEUE_REST));
PendingIntent pendingIntent = PendingIntent.getService(GoroActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(1, new Notification.Builder(GoroActivity.this).setTicker("Click to post to REST").setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true).setContentTitle("Click to post to REST").setContentText("Intent will be sent to the service").setContentIntent(pendingIntent).getNotification());
}
use of android.app.NotificationManager in project Rutgers-Course-Tracker by tevjef.
the class RequestService method makeNotification.
//Creates a notfication of the Android system.
private void makeNotification(Section section, Request r) {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("app_notification", true)) {
String courseTitle = section.getCourse().getTrueTitle();
String sectionNumber = section.getNumber();
//Builds a notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setStyle(new NotificationCompat.BigTextStyle().bigText("Section " + sectionNumber + " of " + courseTitle + " has opened").setBigContentTitle(r.getSemester().toString() + " - " + courseTitle)).setSmallIcon(R.drawable.ic_notification).setWhen(System.currentTimeMillis()).setPriority(NotificationCompat.PRIORITY_MAX).setColor(ContextCompat.getColor(mContext, R.color.green)).setAutoCancel(true).setGroup(SECTION_NOTIFICATION_GROUP).setSound(getSound()).setContentTitle("A section has opened!").setContentText("Section " + sectionNumber + " of " + courseTitle + " has opened");
//Intent to start web browser
Intent openInBrowser = new Intent(Intent.ACTION_VIEW);
openInBrowser.setData(Uri.parse("https://sims.rutgers.edu/webreg/"));
PendingIntent pOpenInBrowser = PendingIntent.getActivity(RequestService.this, 0, openInBrowser, 0);
mBuilder.addAction(R.drawable.ic_open_in_browser_white_24dp, "Webreg", pOpenInBrowser);
//Intent open the app.
Intent openTracked = new Intent(RequestService.this, DatabaseReceiver.class);
openTracked.putExtra(TrackedSectionsView.REQUEST, r);
openTracked.putExtra(CourseInfoView.SELECTED_SECTION, section);
//The intent that will be when the user clicks stop tracking in the notification bar.
PendingIntent pOpenTracked = PendingIntent.getBroadcast(RequestService.this, Integer.valueOf(r.getIndex()), openTracked, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.addAction(R.drawable.ic_close_white_24dp, "Stop Tracking", pOpenTracked);
//When you click on the notification itself.
mBuilder.setContentIntent(pOpenInBrowser);
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//Builds the intent and sends it to notification manager with a unique ID.
// The id is the index number of the section since those are also unique.
// It also allows me to easily update the notication in the future.
Notification n = mBuilder.build();
mNotifyMgr.notify(Integer.valueOf(r.getIndex()), n);
}
}
use of android.app.NotificationManager in project glimmr by brk3.
the class ContactsPhotosNotificationHandler method showNewPhotosNotification.
/** Notify that user's contacts have uploaded new photos */
public void showNewPhotosNotification(List<Photo> newPhotos) {
final NotificationManager mgr = (NotificationManager) mContext.getSystemService(WakefulIntentService.NOTIFICATION_SERVICE);
String tickerText = mContext.getString(R.string.notification_contacts_ticker);
String titleText = String.format("%d %s", newPhotos.size(), mContext.getString(R.string.notification_contacts_title));
String contentText = mContext.getString(R.string.notification_contacts_content);
Notification newContactsPhotos = getNotification(tickerText, titleText, contentText, newPhotos.size());
mgr.notify(Constants.NOTIFICATION_NEW_CONTACTS_PHOTOS, newContactsPhotos);
}
use of android.app.NotificationManager in project glimmr by brk3.
the class UploadPhotoTaskQueueService method clearStartedNotification.
private void clearStartedNotification() {
NotificationCompat.Builder notification = new NotificationCompat.Builder(this).setProgress(0, 0, false).setSmallIcon(R.drawable.ic_action_upload_dark).setAutoCancel(true);
/* if we're stopping because max retries exceeded */
if (mNumRetries >= MAX_RETRIES) {
final Intent intent = new Intent(this, UploadPhotoTaskQueueService.class);
PendingIntent peManualRetry = PendingIntent.getService(this, 0, intent, 0);
notification.setTicker(getString(R.string.upload_problem)).setContentTitle(getString(R.string.upload_problem)).addAction(R.drawable.ic_action_refresh_dark, getString(R.string.retry), peManualRetry).setContentText(getString(R.string.ill_try_again_later));
} else {
notification.setTicker(getString(R.string.photos_uploaded)).setContentTitle(getString(R.string.photos_uploaded)).setContentText(getString(R.string.tap_for_photostream)).setDefaults(Notification.DEFAULT_ALL);
}
final Intent intent = new Intent(this, MainActivity.class);
// open on "Photos" page
intent.putExtra(MainActivity.KEY_PAGER_START_INDEX, 1);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final PendingIntent pe = PendingIntent.getActivity(this, 0, intent, 0);
notification.setContentIntent(pe);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Constants.NOTIFICATION_PHOTOS_UPLOADING, notification.build());
}
use of android.app.NotificationManager in project glimmr by brk3.
the class ActivityNotificationHandler method onItemPhotoReady.
private void onItemPhotoReady(Item item, Photo photo, Bitmap bitmap, int eventOffset) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onItemPhotoReady");
String tickerText = String.format("%s %s", mContext.getString(R.string.new_activity), item.getTitle());
String titleText = item.getTitle();
/* build the notification content text from the item events */
StringBuilder contentText = new StringBuilder();
List<Event> events = (List<Event>) item.getEvents();
List<Event> newEvents = events.subList(eventOffset, events.size());
if (BuildConfig.DEBUG)
Log.d(TAG, "newEvents.size: " + newEvents.size());
for (int i = 0; i < newEvents.size(); i++) {
Event e = newEvents.get(i);
if ("comment".equals(e.getType())) {
contentText.append(String.format("%s %s", e.getUsername(), mContext.getString(R.string.added_a_comment)));
if (i < newEvents.size() - 1 && newEvents.size() > 1) {
contentText.append(", ");
}
} else if ("fave".equals(e.getType())) {
contentText.append(String.format("%s %s", e.getUsername(), mContext.getString(R.string.favorited)));
if (i < newEvents.size() - 1 && newEvents.size() > 1) {
contentText.append(", ");
}
}
if (i == 1 && i < newEvents.size()) {
contentText.append("+ ").append(newEvents.size() - 2).append(" others");
break;
}
}
/* finally, show the notification itself */
int smallIcon = R.drawable.ic_social_chat_dark;
if ("fave".equals(newEvents.get(0).getType())) {
smallIcon = R.drawable.ic_action_rating_important_dark;
}
Notification n = getNotification(tickerText, titleText, contentText.toString(), newEvents.size(), smallIcon, bitmap, photo);
final NotificationManager mgr = (NotificationManager) mContext.getSystemService(WakefulIntentService.NOTIFICATION_SERVICE);
mgr.notify(Constants.NOTIFICATION_NEW_ACTIVITY, n);
}
Aggregations