@Override public boolean onStartJob(JobParameters params) { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle("You added a contact!") .setSmallIcon(android.R.drawable.stat_notify_more); mgr.notify(NOTIFY_ID, b.build()); return(false); }
private void raiseNotification(String contentType, File output, Exception e) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()); if (e == null) { b.setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setSmallIcon(android.R.drawable.stat_sys_download_done); Intent outbound=new Intent(Intent.ACTION_VIEW); outbound.setDataAndType(Uri.fromFile(output), contentType); b.setContentIntent(PendingIntent.getActivity(this, 0, outbound, 0)); } else { b.setContentTitle(getString(R.string.exception)) .setContentText(e.getMessage()) .setSmallIcon(android.R.drawable.stat_notify_error); } mgr.notify(NOTIFY_ID, b.build()); }
private NotificationCompat.Builder buildBase(Context ctxt, String channel, int titleId) { NotificationCompat.Builder b= new NotificationCompat.Builder(ctxt, channel); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(ctxt.getString(titleId)) .setContentIntent(buildPendingIntent(ctxt, Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, ctxt.getString(R.string.play), buildPendingIntent(ctxt, Settings.ACTION_SETTINGS)); return(b); }
Intent ui=new Intent(this, EventDemoActivity.class); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND) .setContentTitle(getString(R.string.notif_title)) .setContentText(Integer.toHexString(random))
Intent ui=new Intent(this, EventDemoActivity.class); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND) .setContentTitle(getString(R.string.notif_title)) .setContentText(Integer.toHexString(randomEvent.value))
Intent ui=new Intent(this, EventDemoActivity.class); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND) .setContentTitle(getString(R.string.notif_title)) .setContentText(Integer.toHexString(randomEvent.value))
void initBuilder(DownloadTask downloadTask) { String title = TextUtils.isEmpty(downloadTask.getFile().getName()) ? mContext.getString(R.string.agentweb_file_download) : downloadTask.getFile().getName(); if (title.length() > 20) { title = "..." + title.substring(title.length() - 20, title.length()); } mBuilder.setContentIntent(PendingIntent.getActivity(mContext, 200, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT)); // 设置顶部状态栏的小图标 mBuilder.setSmallIcon(downloadTask.getDrawableRes()); // 在顶部状态栏中的提示信息 mBuilder.setTicker(mContext.getString(R.string.agentweb_trickter)); // 设置通知中心的标题 mBuilder.setContentTitle(title); // 设置通知中心中的内容 mBuilder.setContentText(mContext.getString(R.string.agentweb_coming_soon_download)); mBuilder.setWhen(System.currentTimeMillis()); mBuilder.setAutoCancel(true); mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); int defaults = 0; this.mUrl = downloadTask.getUrl(); this.mFile = downloadTask.getFile(); mBuilder.setDeleteIntent(buildCancelContent(mContext, downloadTask.getId(), downloadTask.getUrl())); mBuilder.setDefaults(defaults); }
private void foregroundify() { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); b.setContentTitle(getString(R.string.app_name)) .setSmallIcon(R.mipmap.ic_launcher) .setTicker(getString(R.string.app_name)); b.addAction(R.drawable.ic_record_white_24dp, getString(R.string.notify_record), buildPendingIntent(ACTION_RECORD)); b.addAction(R.drawable.ic_eject_white_24dp, getString(R.string.notify_shutdown), buildPendingIntent(ACTION_SHUTDOWN)); startForeground(NOTIFY_ID, b.build()); }
@Override public void onStart() { if (mBuilder == null) { String title = "下载中 - " + mContext.getString(mContext.getApplicationInfo().labelRes); mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setOngoing(true) .setAutoCancel(false) .setPriority(Notification.PRIORITY_MAX) .setDefaults(Notification.DEFAULT_VIBRATE) .setSmallIcon(mContext.getApplicationInfo().icon) .setTicker(title) .setContentTitle(title); } onProgress(0); }
private void raiseNotification(Exception e) { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()); if (e == null) { b.setContentTitle(getString(R.string.download_complete)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setTicker(getString(R.string.download_complete)); } else { b.setContentTitle(getString(R.string.exception)) .setContentText(e.getMessage()) .setSmallIcon(android.R.drawable.stat_notify_error) .setTicker(getString(R.string.exception)); } mgr.notify(NOTIFY_ID, b.build()); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setTicker(getString(R.string.download_complete)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setLocalOnly(true) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
@Subscribe public void onDeadEvent(DeadEvent braiiiiiiinz) { RandomEvent original=(RandomEvent)braiiiiiiinz.event; NotificationCompat.Builder b=new NotificationCompat.Builder(this); Intent ui=new Intent(this, EventDemoActivity.class); b.setAutoCancel(true).setDefaults(Notification.DEFAULT_SOUND) .setContentTitle(getString(R.string.notif_title)) .setContentText(Integer.toHexString(original.value)) .setSmallIcon(android.R.drawable.stat_notify_more) .setTicker(getString(R.string.notif_title)) .setContentIntent(PendingIntent.getActivity(this, 0, ui, 0)); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); mgr.notify(NOTIFY_ID, b.build()); } }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setNumber(5) .setFullScreenIntent(buildPendingIntent(Settings.ACTION_DATE_SETTINGS), true) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationItem(int id, String title, String desc) { super(id, title, desc); Intent[] intents = new Intent[2]; intents[0] = Intent.makeMainActivity(new ComponentName(DemoApplication.CONTEXT, MainActivity.class)); intents[1] = new Intent(DemoApplication.CONTEXT, NotificationSampleActivity.class); this.pendingIntent = PendingIntent.getActivities(DemoApplication.CONTEXT, 0, intents, PendingIntent.FLAG_UPDATE_CURRENT); builder = new NotificationCompat. Builder(FileDownloadHelper.getAppContext()); builder.setDefaults(Notification.DEFAULT_LIGHTS) .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getTitle()) .setContentText(desc) .setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher); }
private NotificationItem(int id, String title, String desc) { super(id, title, desc); Intent[] intents = new Intent[2]; intents[0] = Intent.makeMainActivity(new ComponentName(DemoApplication.CONTEXT, MainActivity.class)); intents[1] = new Intent(DemoApplication.CONTEXT, NotificationSampleActivity.class); this.pendingIntent = PendingIntent.getActivities(DemoApplication.CONTEXT, 0, intents, PendingIntent.FLAG_UPDATE_CURRENT); builder = new NotificationCompat. Builder(FileDownloadHelper.getAppContext()); builder.setDefaults(Notification.DEFAULT_LIGHTS) .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MIN) .setContentTitle(getTitle()) .setContentText(desc) .setContentIntent(pendingIntent) .setSmallIcon(R.mipmap.ic_launcher); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .addAction(android.R.drawable.ic_media_play, getString(R.string.play), buildPendingIntent(Settings.ACTION_SETTINGS)); return(b); }
private NotificationCompat.Builder buildNormal() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.download_complete)) .setContentText(getString(R.string.fun)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE) .setGroupSummary(true); return(b); }
private void showWearTwo() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.another_entry)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE); mgrCompat.notify(NOTIFY_ID3, b.build()); }
private void showWearOne() { NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle(getString(R.string.entry)) .setContentIntent(buildPendingIntent(Settings.ACTION_SECURITY_SETTINGS)) .setSmallIcon(android.R.drawable.stat_sys_download_done) .setGroup(GROUP_SAMPLE); mgrCompat.notify(NOTIFY_ID2, b.build()); }