@Override public void onReceive(Context context, Intent intent) { Intent intent2 = new Intent(context, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent2, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) .setAutoCancel(true) //Automatically delete the notification .setSmallIcon(R.drawable.water_bottle_flat) //Notification icon .setContentIntent(pendingIntent) .setContentTitle("Time to hydrate") .setContentText("Drink a glass of water now") .setCategory(Notification.CATEGORY_REMINDER) .setPriority(Notification.PRIORITY_HIGH) .setSound(defaultSoundUri); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(0, notificationBuilder.build()); Toast.makeText(context, "Repeating Alarm Received", Toast.LENGTH_SHORT).show(); }
private Notification createNotification(){ if(mediaMetadata==null||playbackState==null) return null; NotificationCompat.Builder builder=new NotificationCompat.Builder(service); builder.setStyle(new NotificationCompat.MediaStyle() .setMediaSession(token) .setShowActionsInCompactView(1)) .setColor(Color.WHITE) .setPriority(Notification.PRIORITY_MAX) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setUsesChronometer(true) .setDeleteIntent(dismissedNotification(service)) .setSmallIcon(R.drawable.ic_music_note) .setContentIntent(contentIntent(service)) .setContentTitle(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ARTIST)) .setContentText(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE)) .addAction(prev(service)); if(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING){ builder.addAction(pause(service)); }else{ builder.addAction(play(service)); } builder.addAction(next(service)); setNotificationPlaybackState(builder); loadImage(mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI),builder); return builder.build(); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(TAG, "WhiteService->onStartCommand"); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentTitle("Foreground"); builder.setContentText("I am a foreground service"); builder.setContentInfo("Content Info"); builder.setWhen(System.currentTimeMillis()); Intent activityIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); Notification notification = builder.build(); startForeground(FOREGROUND_ID, notification); return super.onStartCommand(intent, flags, startId); }
@Override public void onReceive(Context context, Intent intent) { NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder( context ); builder.setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Test") .setContentText( intent.getStringExtra("text") ) .setSubText("Three Line") .setContentInfo("info") .setWhen( System.currentTimeMillis() ); manager.notify(0, builder.build()); Log.d("onReceive", "はいったお!!!!!!!!"); }
@Override protected void onPreExecute() { b = new NotificationCompat.Builder(context); nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent resultIntent = new Intent(context, MainActivity.class); resultPendingIntent = PendingIntent.getActivity( context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT ); b.setAutoCancel(false) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.icon)) .setSmallIcon(R.drawable.ic_battery_mgr_mod) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentIntent(resultPendingIntent) .setOngoing(true) ; }
private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("FCM Message") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
private Notification createNotification() { LighthouseTrack track = service.getTrack(); Podcast podcast = track.getPodcast(); Record record = track.getRecord(); RemoteViews remoteViews = new RemoteViews(service.getPackageName(), R.layout.notification); RemoteViews bigRemoteViews = new RemoteViews(service.getPackageName(), R.layout.notification_big); notificationBuilder.setSmallIcon(R.drawable.notification_icon) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setContentTitle(podcast.getName()) .setContent(remoteViews) .setCustomBigContentView(bigRemoteViews) .setContentIntent(createContentIntent(podcast, record)); setRecordState(remoteViews, podcast, record); setRecordState(bigRemoteViews, podcast, record); setPlayPauseState(remoteViews); setPlayPauseState(bigRemoteViews); setNotificationPlaybackState(bigRemoteViews); return notificationBuilder.build(); }
/** * save one activity record * @param activityRecord record to save * @return the file path this record is saved */ public static boolean saveOneRecord(ActivityRecord activityRecord) { boolean ret = saveOneRecord(activityRecord.toJsonString()); if (ret) { Application app = StallBuster.getInstance().getApp(); Intent intent = new Intent(StallBuster.getInstance().getApp(), ReportListActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(StallBuster.getInstance().getApp(), 1, intent, FLAG_UPDATE_CURRENT); NotificationManager nm = (NotificationManager)app.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(NOTIFICATION_ID); Notification notification = new NotificationCompat.Builder(app) .setAutoCancel(true) .setContentTitle(app.getString(R.string.notification_title, activityRecord.cost, activityRecord.activity_name)) .setContentText(app.getString(R.string.notification_text)) .setSmallIcon(android.R.drawable.sym_def_app_icon) .setContentIntent(pendingIntent) .build(); nm.notify(NOTIFICATION_ID, notification); } return ret; }
private NotificationCompat.Builder mainNotification() { if (mainNotification == null) { mainNotification = new NotificationCompat.Builder(this); mainNotification.setAutoCancel(false); mainNotification.setSmallIcon(R.drawable.ic_play); // Close app on dismiss Intent intentDismiss = new Intent(this, NotificationDismissedReceiver.class); intentDismiss.putExtra("com.my.app.notificationId", notificationId); PendingIntent pendingDelete = PendingIntent.getBroadcast(this, notificationId, intentDismiss, 0); mainNotification.setDeleteIntent(pendingDelete); // Set focus to MainActivity Intent intent = new Intent(Intent.ACTION_MAIN); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pendingContent = PendingIntent.getBroadcast(this, notificationId, intent, 0); mainNotification.setContentIntent(pendingContent); } return mainNotification; }
/** * led command notification * @param argbColor led color * @return running result */ public boolean notifyCommand(int argbColor) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (argbColor == COLOR.NONE.getLocalColor()) { notificationManager.cancel(NOTIFICATION_ID); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.mipmap.icon_color_big); builder.setContentTitle(context.getResources().getString(R.string.actuator_led_notification)); builder.setLights(argbColor, 1000, 0); notificationManager.notify(NOTIFICATION_ID, builder.build()); } return true; }
private void sendNotification(String messageBody) { Intent intent = new Intent(this, StartingActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.bee_logo_app) .setContentTitle("Alert") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
/** * Build a notification using the information from the given media session. Makes heavy use * of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information. * * @param context Context used to construct the notification. * @param mediaSession Media session to get information. * @return A pre-built notification with information from the given media session. */ static NotificationCompat.Builder from( Context context, MediaSessionCompat mediaSession) { MediaControllerCompat controller = mediaSession.getController(); MediaMetadataCompat mediaMetadata = controller.getMetadata(); MediaDescriptionCompat description = mediaMetadata.getDescription(); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder .setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setSubText(description.getDescription()) .setLargeIcon(description.getIconBitmap()) .setContentIntent(controller.getSessionActivity()) .setDeleteIntent( MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP)) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); return builder; }
private void showTranslateInfo(final Translate translate){ String result=translate.getTranslation()[0]; NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(ClipboardService.this) .setSmallIcon(R.drawable.small_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher)) .setContentTitle(getString(R.string.app_name)) .setContentText(result) .setWhen(System.currentTimeMillis()) .setPriority(Notification.PRIORITY_DEFAULT) .setStyle(new NotificationCompat.BigTextStyle().bigText(result)); Intent shareIntent = new Intent().setAction(Intent.ACTION_SEND).setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT,result); PendingIntent sharePi = PendingIntent.getActivity(ClipboardService.this,0,shareIntent,0); mBuilder.addAction(R.drawable.ic_share_white_24dp,getString(R.string.share),sharePi); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(0,mBuilder.build()); }
static public void showNotification(Context context, String msg) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); notificationManager.notify(1, new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification_icon) .setColor(Util.getColor(context, R.color.colorPrimary)) .setContentTitle(context.getString(R.string.app_name)) .setContentText(msg) .setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle() .bigText(msg)) .build()); }
/** * Creates the notification * * @param messageResId * message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults * signals that will be used to notify the user */ private void createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, HTSActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_hts); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.hts_notification_action_disconnect), disconnectAction)); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notification); }
/** * Creates the notification * * @param messageResId * message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults * signals that will be used to notify the user */ private void createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, RSCActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_rsc); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.rsc_notification_action_disconnect), disconnectAction)); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notification); }
/** * Creates the notification * * @param messageResId * message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults * signals that will be used to notify the user */ private void createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, UARTActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); disconnect.putExtra(EXTRA_SOURCE, SOURCE_NOTIFICATION); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_uart); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.uart_notification_action_disconnect), disconnectAction)); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notification); }
/** * Creates the notification * * @param messageResId * message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults * signals that will be used to notify the user */ private void createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, TemplateActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_template); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.template_notification_action_disconnect), disconnectAction)); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notification); }
/** * Creates the notification * * @param messageResId * the message resource id. The message must have one String parameter,<br /> * f.e. <code><string name="name">%s is connected</string></code> * @param defaults * signals that will be used to notify the user */ private void createNotification(final int messageResId, final int defaults) { final Intent parentIntent = new Intent(this, FeaturesActivity.class); parentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); final Intent targetIntent = new Intent(this, CSCActivity.class); final Intent disconnect = new Intent(ACTION_DISCONNECT); final PendingIntent disconnectAction = PendingIntent.getBroadcast(this, DISCONNECT_REQ, disconnect, PendingIntent.FLAG_UPDATE_CURRENT); // both activities above have launchMode="singleTask" in the AndroidManifest.xml file, so if the task is already running, it will be resumed final PendingIntent pendingIntent = PendingIntent.getActivities(this, OPEN_ACTIVITY_REQ, new Intent[] { parentIntent, targetIntent }, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle(getString(R.string.app_name)).setContentText(getString(messageResId, getDeviceName())); builder.setSmallIcon(R.drawable.ic_stat_notify_csc); builder.setShowWhen(defaults != 0).setDefaults(defaults).setAutoCancel(true).setOngoing(true); builder.addAction(new NotificationCompat.Action(R.drawable.ic_action_bluetooth, getString(R.string.csc_notification_action_disconnect), disconnectAction)); final Notification notification = builder.build(); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notification); }
private NotificationCompat.Builder createNotificationBuilder() { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); notificationBuilder .setSmallIcon(R.mipmap.ic_launcher) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setUsesChronometer(true) .setContentIntent(createContentIntent()) .setContentTitle("快手抢红包"); // 播放持续时间, 不显示了 notificationBuilder.setWhen(0) .setShowWhen(false) .setUsesChronometer(false); // 确保通知可以被用户当我们不玩: notificationBuilder.setOngoing(mService.isRun()); return notificationBuilder; }
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { if (mPlaybackState == null || !mStarted) { mService.stopForeground(true); return; } if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) { builder .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition()) .setShowWhen(true) .setUsesChronometer(true); } else { builder .setWhen(0) .setShowWhen(false) .setUsesChronometer(false); } // Make sure that the notification can be dismissed by the user when we are not playing: builder.setOngoing(mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING); }
private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) { NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.addLine(message); Notification notification; notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0) .setAutoCancel(true) .setContentTitle(title) .setContentIntent(resultPendingIntent) .setSound(alarmSound) .setStyle(inboxStyle) .setWhen(getTimeMilliSec(timeStamp)) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon)) .setContentText(message) .build(); NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Config.NOTIFICATION_ID, notification); }
private void sendNotification(Context context, String title, String text, Bitmap contactPhoto) { boolean lollipop = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP; if (lollipop && contactPhoto != null) { int side = Math.min(contactPhoto.getWidth(), contactPhoto.getHeight()); contactPhoto = CustodeUtils.getRoundedBitmap(contactPhoto, side, side); } Notification notification = new NotificationCompat.Builder(context) .setAutoCancel(true) .setContentText(text) .setContentTitle(title) .setLargeIcon(contactPhoto) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setStyle(new NotificationCompat.BigTextStyle().bigText(text)) .setColor(ContextCompat.getColor(context, R.color.light_blue_A400)) .setSmallIcon(lollipop ? R.drawable.ic_notification : R.mipmap.ic_launcher) .build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); }
@Override public void build() { super.build(); NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle(); if(bitmap==null || bitmap.isRecycled()){ if(bigPic >0){ final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = true; options.inSampleSize = 2; bitmap = BitmapFactory.decodeResource(NotifyUtil.getInstance().getContext().getResources(), bigPic, options); } } picStyle.bigPicture(bitmap); //picStyle.bigLargeIcon(bitmap); picStyle.setBigContentTitle(contentTitle); picStyle.setSummaryText(summaryText); cBuilder.setStyle(picStyle); }
/** * Returns the {@link NotificationCompat.Action} for forwarding the current media by * {@code millis} milliseconds. */ protected NotificationCompat.Action getForwardAction(long millis) { Intent intent = new Intent(this, VideoIntentReceiver.class); intent.setAction(ACTION_FORWARD); intent.setPackage(getPackageName()); intent.putExtra(EXTRA_FORWARD_STEP_MS, (int) millis); PendingIntent pendingIntent = PendingIntent .getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int iconResourceId = R.drawable.ic_notification_forward_48dp; if (millis == TEN_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_forward10_48dp; } else if (millis == THIRTY_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_forward30_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_forward), pendingIntent).build(); }
/** * Returns the {@link NotificationCompat.Action} for rewinding the current media by * {@code millis} milliseconds. */ protected NotificationCompat.Action getRewindAction(long millis) { Intent intent = new Intent(this, VideoIntentReceiver.class); intent.setAction(ACTION_REWIND); intent.setPackage(getPackageName()); intent.putExtra(EXTRA_FORWARD_STEP_MS, (int)-millis); PendingIntent pendingIntent = PendingIntent .getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int iconResourceId = R.drawable.ic_notification_rewind_48dp; if (millis == TEN_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_rewind10_48dp; } else if (millis == THIRTY_SECONDS_MILLIS) { iconResourceId = R.drawable.ic_notification_rewind30_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_rewind), pendingIntent).build(); }
/** * Returns the {@link NotificationCompat.Action} for skipping to the next item in the queue. If * we are already at the end of the queue, we show a dimmed version of the icon for this action * and won't send any {@link PendingIntent} */ protected NotificationCompat.Action getSkipNextAction() { PendingIntent pendingIntent = null; int iconResourceId = R.drawable.ic_notification_skip_next_semi_48dp; if (mHasNext) { Intent intent = new Intent(this, VideoIntentReceiver.class); intent.setAction(ACTION_PLAY_NEXT); intent.setPackage(getPackageName()); pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); iconResourceId = R.drawable.ic_notification_skip_next_48dp; } return new NotificationCompat.Action.Builder(iconResourceId, getString(R.string.ccl_skip_next), pendingIntent).build(); }
/** * Returns the {@link NotificationCompat.Action} for toggling play/pause/stop of the currently * playing item. */ protected NotificationCompat.Action getPlayPauseAction(MediaInfo info, boolean isPlaying) { int pauseOrStopResourceId; if (info.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) { pauseOrStopResourceId = R.drawable.ic_notification_stop_48dp; } else { pauseOrStopResourceId = R.drawable.ic_notification_pause_48dp; } int pauseOrPlayTextResourceId = isPlaying ? R.string.ccl_pause : R.string.ccl_play; int pauseOrPlayResourceId = isPlaying ? pauseOrStopResourceId : R.drawable.ic_notification_play_48dp; Intent intent = new Intent(this, VideoIntentReceiver.class); intent.setAction(ACTION_TOGGLE_PLAYBACK); intent.setPackage(getPackageName()); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); return new NotificationCompat.Action.Builder(pauseOrPlayResourceId, getString(pauseOrPlayTextResourceId), pendingIntent).build(); }
private void setNotificationPlaybackState(NotificationCompat.Builder builder) { if (playbackState == null || !isStarted) { return; } if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING && playbackState.getPosition() >= 0) { builder.setWhen(System.currentTimeMillis() - playbackState.getPosition()) .setShowWhen(true) .setUsesChronometer(true); } else { builder.setWhen(0) .setShowWhen(false) .setUsesChronometer(false); } builder.setOngoing(playbackState.getState()==PlaybackStateCompat.STATE_PLAYING); }
void reminder() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setSmallIcon(R.drawable.sos); mBuilder.setContentTitle("Reminder !"); mBuilder.setContentText(reminder_text); Intent resultIntent = new Intent(this, Location_event.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(Location_event.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // notificationID allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); }
private void displayNotification(Context context, String message) { NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager == null) { Toast.makeText(context, "InitialVolume: Unable to get NotificationManager", Toast.LENGTH_SHORT).show(); return; } notificationManager.notify(notificationID, new NotificationCompat.Builder(context).setSmallIcon(R.mipmap.ic_launcher).setContentTitle("InitialVolume").setContentText(message).build()); notificationID++; }
private void initNotification() { int icon = R.mipmap.bike_icon2; contentView = new RemoteViews(getPackageName(), R.layout.notification_layout); notification = new NotificationCompat.Builder(this).setContent(contentView).setSmallIcon(icon).build(); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra("flag", "notification"); notification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); }
public static void showNewPostNotifications(){ if (!Prefs.NotificationsEnabled()){ return; } notificationPosts = PostRepository.getUnSeen(); android.support.v4.app.NotificationCompat.InboxStyle inboxStyle = new android.support.v4.app.NotificationCompat.InboxStyle(); for(Post post : notificationPosts){ inboxStyle.addLine(post.getTitle()); } //Notification sound SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(App.getAppContext()); String strRingtonePreference = preference.getString("notifications_new_message_ringtone", "DEFAULT_SOUND"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(App.getAppContext()); mBuilder.setSmallIcon(R.drawable.ic_notifications) .setColor(App.getAppContext().getResources().getColor(R.color.brandColor)) .setSound(Uri.parse(strRingtonePreference)) .setAutoCancel(true) .setContentTitle("Laravel News") .setContentText(getSummaryMessage()) .setContentIntent(getNotificationIntent()) .setStyle(inboxStyle) .setGroup("LNA_NOTIFICATIONS_GROUP"); //Check the vibrate if(Prefs.NotificationVibrateEnabled()){ mBuilder.setVibrate(new long[] {1000,1000}); } Notification notification = mBuilder.build(); // Issue the group notification NotificationManagerCompat notificationManager = NotificationManagerCompat.from(App.getAppContext()); notificationManager.notify(1, notification); }
@Override public void build() { super.build(); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (String msg : messageList) { inboxStyle.addLine(msg); } String text = "[" + messageList.size() + "]条信息"; inboxStyle.setSummaryText(text); cBuilder.setStyle(inboxStyle); cBuilder.setContentText("你有"+text); if(TextUtils.isEmpty(ticker)){ cBuilder.setTicker(text); } }
@Override public void onAccessibilityEvent(AccessibilityEvent event) { SharedPreferences sharedPreferences = getSharedPreferences("nico.styTool_preferences", MODE_PRIVATE); boolean isFirstRun = sharedPreferences.getBoolean("ok_c", true); //Editor editor = sharedPreferences.edit(); if (isFirstRun) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentTitle("妮媌"); builder.setContentText("QQ抢红包正在运行"); builder.setOngoing(true); Notification notification = builder.build(); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID, notification); } else { } if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { List<CharSequence> texts = event.getText(); if (!texts.isEmpty()) { for (CharSequence text : texts) { String content = text.toString(); if (content.contains(QQ_KEYWORD_NOTIFICATION)) { openNotify(event); return; } } } } openHongBao(event); }
void stopData() { try { setMobileDataEnabled(this.getApplicationContext(), false); } catch(Exception e){ // Toast.makeText(this,e.toString(),Toast.LENGTH_SHORT).show(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setSmallIcon(R.drawable.sos); mBuilder.setContentTitle("Reminder !"); mBuilder.setContentText(e.toString()); Intent resultIntent = new Intent(this, Location_event.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(Location_event.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // notificationID allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); } }
private android.support.v4.app.NotificationCompat.Builder getBuilder() { if (this.builder == null) { this.builder = new NotificationCompat.Builder(this.cordova.getActivity()).setSmallIcon(getResource("launcher_icon")); } return this.builder; }
public static void createStopNotification(MediaSessionCompat mediaSession, Service context, Class<?> serviceClass, int NOTIFICATION_ID) { PendingIntent stopIntent = PendingIntent .getService(context, 0, getIntent(MediaRecorderService.REQUEST_TYPE_STOP, context, serviceClass), PendingIntent.FLAG_CANCEL_CURRENT); MediaControllerCompat controller = mediaSession.getController(); MediaMetadataCompat mediaMetadata = controller.getMetadata(); MediaDescriptionCompat description = mediaMetadata.getDescription(); // Start foreground service to avoid unexpected kill Notification notification = new NotificationCompat.Builder(context) .setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()) .setSubText(description.getDescription()) .setLargeIcon(description.getIconBitmap()) .setDeleteIntent(stopIntent) // Add a pause button .addAction(new android.support.v7.app.NotificationCompat.Action( R.drawable.ic_stop_black_24dp, context.getString(R.string.stop), MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))) .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle() .setMediaSession(mediaSession.getSessionToken()) .setShowActionsInCompactView(0) .setShowCancelButton(true) .setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))) .setSmallIcon(R.drawable.ic_album_black_24dp) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .build(); context.startForeground(NOTIFICATION_ID, notification); }
/** * 发送通知到通知栏 * * @param isAllowVibrate 是否允许振动 * @param isAllowVoice 是否允许声音 * @param context context * @param title 标题 * @param icon 图标 * @param content 内容 * @param targetClass 目标Activity */ public void notify(String tag, String groupId, boolean isAllowVibrate, boolean isAllowVoice, Context context, String title, int icon, CharSequence content, Class<? extends Activity> targetClass) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon); builder.setContentText(content); builder.setContentTitle(title); builder.setTicker(title); builder.setAutoCancel(true); if (isAllowVibrate) { builder.setDefaults(Notification.DEFAULT_VIBRATE); } if (isAllowVoice) { builder.setDefaults(Notification.DEFAULT_SOUND); } LogUtil.e("设置通知123"); if (targetClass!=null) { Intent intent = new Intent(context, targetClass); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(Constant.NOTIFICATION_TAG, tag); if (groupId != null) { intent.putExtra("groupId", groupId); } PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } sNotificationManager.notify(Constant.NOTIFY_ID, builder.build()); sNotificationManager.notify(Constant.NOTIFY_ID, builder.build()); }
@Override public void onCreate() { super.onCreate(); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder builder= new NotificationCompat.Builder(getApplicationContext()); builder.setContentTitle(getString(R.string.time_to_practice)); builder.setContentText(getString(R.string.it_is_time_to_practice)); builder.setSmallIcon(R.drawable.sym_action_email); mNotificationManager.notify(mNotificationId,builder.build()); }