List of usage examples for android.app Notification.Builder setSmallIcon
@UnsupportedAppUsage public void setSmallIcon(Icon icon)
From source file:com.mishiranu.dashchan.content.service.PostingService.java
@Override public void run() { boolean interrupted = false; while (true) { TaskState taskState = null;//w w w . j av a2 s .com if (!interrupted) { try { taskState = notificationsQueue.take(); } catch (InterruptedException e) { interrupted = true; } } if (interrupted) { taskState = notificationsQueue.poll(); } if (taskState == null) { return; } if (taskState.cancel) { notificationManager.cancel(taskState.notificationId); } else { Notification.Builder builder = taskState.builder; if (taskState.first) { builder.setOngoing(true); builder.setSmallIcon(android.R.drawable.stat_sys_upload); PendingIntent cancelIntent = PendingIntent.getService( this, taskState.notificationId, new Intent(this, PostingService.class) .setAction(ACTION_CANCEL_POSTING).putExtra(EXTRA_KEY, taskState.key), PendingIntent.FLAG_UPDATE_CURRENT); Context themedContext = new ContextThemeWrapper(this, R.style.Theme_Special_Notification); ViewUtils.addNotificationAction(builder, this, ResourceUtils.getResourceId(themedContext, R.attr.notificationCancel, 0), getString(android.R.string.cancel), cancelIntent); if (C.API_LOLLIPOP) { setNotificationColor(builder); } } boolean progressMode = taskState.task.isProgressMode(); switch (taskState.progressState) { case CONNECTING: { if (progressMode) { builder.setProgress(1, 0, true); } builder.setContentTitle(getString(R.string.message_sending)); break; } case SENDING: { if (progressMode) { builder.setProgress(taskState.progressMax, taskState.progress, taskState.progressMax <= 0); builder.setContentTitle(getString(R.string.message_sending_index_format, taskState.attachmentIndex + 1, taskState.attachmentsCount)); } else { builder.setContentTitle(getString(R.string.message_sending)); } break; } case PROCESSING: { if (progressMode) { builder.setProgress(1, 1, false); } builder.setContentTitle(getString(R.string.message_processing_data)); break; } } builder.setContentText(taskState.text); notificationManager.notify(taskState.notificationId, builder.build()); } } }
From source file:org.openbmap.services.MasterBrainService.java
/** * Shows Android notification while this service is running. *///from ww w .j a v a 2s .c o m private void showNotification() { PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, TabHostActivity.class), 0); // Set the icon, scrolling text and timestamp //final Notification notification = new Notification(R.drawable.icon_greyed_25x25, getString(R.string.notification_caption), // System.currentTimeMillis()); //notification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification_caption), contentIntent); // Set the info for the views that show in the notification panel. if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); builder.setAutoCancel(false); builder.setContentTitle(getString(R.string.app_name)); builder.setContentText(getString(R.string.notification_caption)); builder.setSmallIcon(R.drawable.icon_greyed_25x25); builder.setContentIntent(intent); builder.setOngoing(true); mNotificationManager.notify(NOTIFICATION_ID, builder.build()); } else if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN) { NotificationCompat.Builder compat = new NotificationCompat.Builder(getApplicationContext()); compat.setAutoCancel(false); compat.setContentTitle(getString(R.string.app_name)); compat.setContentText(getString(R.string.notification_caption)); compat.setSmallIcon(R.drawable.icon_greyed_25x25); compat.setContentIntent(intent); compat.setOngoing(true); mNotificationManager.notify(NOTIFICATION_ID, compat.build()); } }
From source file:com.magnet.mmx.client.MMXWakeupIntentService.java
private void invokeNotificationForPush(GCMPayload payload) { // Launch the activity with action=MAIN, category=DEFAULT. Make sure that // it has DEFAULT category declared in AndroidManifest.xml intent-filter. PendingIntent intent = PendingIntent.getActivity(this.getApplicationContext(), 0, new Intent(Intent.ACTION_MAIN).setPackage(this.getPackageName()) .addCategory(Intent.CATEGORY_DEFAULT) // it is redundant .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED), PendingIntent.FLAG_UPDATE_CURRENT); // If title is not specified, use the app name (compatible with iOS push notification) String title = (payload.getTitle() == null) ? this.getApplicationInfo().name : payload.getTitle(); Notification.Builder noteBuilder = new Notification.Builder(this).setContentIntent(intent) .setAutoCancel(true).setWhen(System.currentTimeMillis()).setContentTitle(title) .setContentText(payload.getBody()); if (payload.getSound() != null) { // TODO: cannot handle custom sound yet; use notification ring tone. noteBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); }//from w w w . j a v a2 s. c o m if (payload.getIcon() != null) { noteBuilder.setSmallIcon( this.getResources().getIdentifier(payload.getIcon(), "drawable", this.getPackageName())); } else { noteBuilder.setSmallIcon(this.getApplicationInfo().icon); } if (payload.getBadge() != null) { noteBuilder.setNumber(payload.getBadge()); } NotificationManager noteMgr = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); noteMgr.notify(sNoteId++, noteBuilder.build()); }
From source file:support.plus.reportit.SettingsActivity.java
public Notification getNotification(String content) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); final SharedPreferences pref5 = getApplicationContext().getSharedPreferences("soundNotifications", MODE_PRIVATE);/*from w w w .j a v a 2s. c o m*/ String soundUri2 = pref5.getString("alarmSound", String.valueOf(uri)); Notification.Builder builder = new Notification.Builder(this); builder.setContentTitle(getString(R.string.wrap_up)); builder.setContentText(getString(R.string.wrap_up_desc)); builder.setVibrate(new long[] { 1000 }); builder.setSound(Uri.parse(soundUri2)); builder.setPriority(Notification.PRIORITY_MAX); builder.setLights(Color.GREEN, 3000, 3000); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setAutoCancel(true); builder.setContentIntent(PendingIntent.getActivity(this, 1, new Intent(this, AllReportsRV.class), PendingIntent.FLAG_UPDATE_CURRENT)); return builder.build(); }
From source file:org.hopestarter.wallet.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(@Nullable final Address address, final Coin amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;/* w w w .j a v a 2 s . c o m*/ notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (address != null && !notificationAddresses.contains(address)) notificationAddresses.add(address); final MonetaryFormat btcFormat = config.getFormat(); final String packageFlavor = application.applicationPackageFlavor(); final String msgSuffix = packageFlavor != null ? " [" + packageFlavor + "]" : ""; final String tickerMsg = getString(R.string.notification_coins_received_msg, btcFormat.format(amount)) + msgSuffix; final String msg = getString(R.string.notification_coins_received_msg, btcFormat.format(notificationAccumulatedAmount)) + msgSuffix; final StringBuilder text = new StringBuilder(); for (final Address notificationAddress : notificationAddresses) { if (text.length() > 0) text.append(", "); final String addressStr = notificationAddress.toString(); final String label = AddressBookProvider.resolveLabel(getApplicationContext(), addressStr); text.append(label != null ? label : addressStr); } final Notification.Builder notification = new Notification.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); if (text.length() > 0) notification.setContentText(text); notification.setContentIntent( PendingIntent.getActivity(this, 0, new Intent(this, MainTabbedActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:systems.soapbox.ombuds.client.btc.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(@Nullable final Address address, final Coin amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;//from www. ja v a 2s . com notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (address != null && !notificationAddresses.contains(address)) notificationAddresses.add(address); final MonetaryFormat btcFormat = config.getFormat(); final String packageFlavor = application.applicationPackageFlavor(); final String msgSuffix = packageFlavor != null ? " [" + packageFlavor + "]" : ""; final String tickerMsg = getString(R.string.notification_coins_received_msg, btcFormat.format(amount)) + msgSuffix; final String msg = getString(R.string.notification_coins_received_msg, btcFormat.format(notificationAccumulatedAmount)) + msgSuffix; final StringBuilder text = new StringBuilder(); for (final Address notificationAddress : notificationAddresses) { if (text.length() > 0) text.append(", "); final String addressStr = notificationAddress.toString(); final String label = AddressBookProvider.resolveLabel(getApplicationContext(), addressStr); text.append(label != null ? label : addressStr); } final Notification.Builder notification = new Notification.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); if (text.length() > 0) notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:biz.wiz.android.wallet.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(@Nullable final Address from, @Nonnull final Coin amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;/*w w w .ja v a2 s. c o m*/ notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final MonetaryFormat btcFormat = config.getFormat(); final String packageFlavor = application.applicationPackageFlavor(); final String msgSuffix = packageFlavor != null ? " [" + packageFlavor + "]" : ""; final String tickerMsg = getString(R.string.notification_coins_received_msg, btcFormat.format(amount)) + msgSuffix; final String msg = getString(R.string.notification_coins_received_msg, btcFormat.format(notificationAccumulatedAmount)) + msgSuffix; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); final String addressStr = address.toString(); final String label = AddressBookProvider.resolveLabel(getApplicationContext(), addressStr); text.append(label != null ? label : addressStr); } final Notification.Builder notification = new Notification.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); if (text.length() > 0) notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:com.tcity.android.sync.SyncService.java
private void notify(@NotNull String buildConfigurationId, @NotNull String parentProjectId, int size) { Notification.Builder builder = new Notification.Builder(this); String title = size + " new build" + (size == 1 ? "" : "s"); String projectName = myDB.getProjectName(parentProjectId); String buildConfigurationName = myDB.getBuildConfigurationName(buildConfigurationId); Intent activityIntent = new Intent(this, BuildConfigurationOverviewActivity.class); activityIntent.putExtra(BuildConfigurationOverviewActivity.ID_INTENT_KEY, buildConfigurationId); activityIntent.setAction(Long.toString(System.currentTimeMillis())); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, activityIntent, 0); //noinspection deprecation Notification notification = builder.setSmallIcon(R.drawable.ic_launcher).setContentTitle(title) .setContentText(projectName + " - " + buildConfigurationName).setContentIntent(contentIntent) .setAutoCancel(true).getNotification(); myManager.notify(buildConfigurationId.hashCode(), notification); }
From source file:com.matthewmitchell.peercoin_android_wallet.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(@Nullable final Address from, @Nonnull final Coin amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;//from w ww .j a v a 2 s .co m notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final MonetaryFormat ppcFormat = config.getFormat(); final String packageFlavor = application.applicationPackageFlavor(); final String msgSuffix = packageFlavor != null ? " [" + packageFlavor + "]" : ""; final String tickerMsg = getString(R.string.notification_coins_received_msg, ppcFormat.format(amount)) + msgSuffix; final String msg = getString(R.string.notification_coins_received_msg, ppcFormat.format(notificationAccumulatedAmount)) + msgSuffix; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); final String addressStr = address.toString(); final String label = AddressBookProvider.resolveLabel(getApplicationContext(), addressStr); text.append(label != null ? label : addressStr); } final Notification.Builder notification = new Notification.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); if (text.length() > 0) notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
/** * Builds and displays a notification for the given CalEvent. This method uses the new * Notification API to place an action button in the notification. * * @param event the CalEvent that is currently active *//*from w w w . j ava 2 s . com*/ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void displayNewEventNotification(EventInstance event) { // clicking the notification should take the user to the app Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // FLAG_CANCEL_CURRENT is required to make sure that the extras are including in // the new pending intent PendingIntent pendIntent = PendingIntent.getActivity(context, REQUEST_CODES.EVENT_OPEN_MAIN, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification.Builder notBuilder = new Notification.Builder(context) .setContentTitle(context.getString(R.string.notification_event_active_title)) .setContentText(event.toString()).setAutoCancel(false).setOnlyAlertOnce(true).setOngoing(true) .setContentIntent(pendIntent); EventManager eventManager = new EventManager(context, event); switch (eventManager.getBestRinger()) { case SILENT: notBuilder.setSmallIcon(R.drawable.not_silence); break; case VIBRATE: notBuilder.setSmallIcon(R.drawable.not_vibrate); break; case NORMAL: notBuilder.setSmallIcon(R.drawable.not_normal); break; } // this intent will be attached to the button on the notification Intent skipEventIntent = new Intent(context, SkipEventService.class); skipEventIntent.putExtra(SkipEventService.EVENT_ID_TAG, event.getId()); PendingIntent skipEventPendIntent = PendingIntent.getService(context, REQUEST_CODES.EVENT_IGNORE, skipEventIntent, PendingIntent.FLAG_CANCEL_CURRENT); notBuilder.addAction(R.drawable.not_ignore, context.getString(R.string.notification_event_skip), skipEventPendIntent); //an intent to add an additional 15 minutes of silencing for an event Intent addSilencingIntent = new Intent(context, ExtendEventService.class); addSilencingIntent.putExtra(ExtendEventService.INSTANCE_ID, event.getId()); addSilencingIntent.putExtra(ExtendEventService.NEW_EXTEND_LENGTH, event.getExtendMinutes() + 15); //TODO use minutes stored in prefs PendingIntent addSilenceingPendIntent = PendingIntent.getService(context, REQUEST_CODES.EVENT_ADD_TIME, addSilencingIntent, PendingIntent.FLAG_CANCEL_CURRENT); Authenticator authenticator = new Authenticator(context); if (authenticator.isAuthenticated()) { notBuilder.addAction(R.drawable.not_clock, "+15", addSilenceingPendIntent); } // the ticker text should only be shown the first time the notification is // created, not on each update notBuilder .setTicker(context.getString(R.string.notification_event_active_starting) + " " + event.toString()); if (Build.VERSION.SDK_INT >= 21) { notBuilder.setVisibility(Notification.VISIBILITY_PRIVATE); Notification.Builder publicNotification = getBaseEventNotificationBuilder(); publicNotification.setContentTitle(context.getString(R.string.notification_event_active_title_public)); publicNotification.setContentIntent(pendIntent); notBuilder.setPublicVersion(publicNotification.build()); notBuilder.setColor(context.getResources().getColor(R.color.accent)); Drawable d = context.getResources().getDrawable(R.drawable.shape_circle); int height = (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_height); int width = (int) context.getResources().getDimension(android.R.dimen.notification_large_icon_width); d.setBounds(0, 0, width, height); d.mutate().setColorFilter(event.getDisplayColor(), PorterDuff.Mode.MULTIPLY); DatabaseInterface databaseInterface = DatabaseInterface.getInstance(context); String calendarTitle = databaseInterface.getCalendarNameForId(event.getCalendarId()); String c = ""; if (calendarTitle != null && calendarTitle != "") { c = ((Character) calendarTitle.charAt(0)).toString().toUpperCase(); } Bitmap largeIcon = createMarkerIcon(d, c, width, height); // Bitmap largeIcon = combineDrawablesToBitmap(d, getRingerIconForEvent(event), width, height); notBuilder.setLargeIcon(largeIcon); } NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notBuilder.build()); }