本文整理汇总了Java中android.app.Notification.FLAG_ONGOING_EVENT属性的典型用法代码示例。如果您正苦于以下问题:Java Notification.FLAG_ONGOING_EVENT属性的具体用法?Java Notification.FLAG_ONGOING_EVENT怎么用?Java Notification.FLAG_ONGOING_EVENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.FLAG_ONGOING_EVENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldBeFilteredOut
private boolean shouldBeFilteredOut(StatusBarNotification sbn) {
Notification notification = sbn.getNotification();
if (AndroidVersion.isAtLeastOreo()) {
getCurrentRanking().getRanking(sbn.getKey(), mTempRanking);
if (!mTempRanking.canShowBadge()) {
return true;
}
if (mTempRanking.getChannel().getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID)) {
// Special filtering for the default, legacy "Miscellaneous" channel.
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
return true;
}
}
}
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0) {
return true;
}
boolean isGroupHeader = (notification.flags & Notification.FLAG_GROUP_SUMMARY) != 0;
CharSequence title = notification.extras.getCharSequence(Notification.EXTRA_TITLE);
CharSequence text = notification.extras.getCharSequence(Notification.EXTRA_TEXT);
boolean missingTitleAndText = TextUtils.isEmpty(title) && TextUtils.isEmpty(text);
return (isGroupHeader || missingTitleAndText);
}
示例2: showGPSTrackNotification
public static Notification showGPSTrackNotification(Context context, int what) {
GPSTrackNotificationBuilder notificationBuilder =
new GPSTrackNotificationBuilder(context, what);
// Gets an instance of the NotificationManager service
// NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Builds the notification and issues it.
Notification notification = notificationBuilder.build();
if (what == AndiCarNotification.GPS_TRACKING_IN_PROGRESS_ID
|| what == AndiCarNotification.GPS_TRACKING_PAUSED_ID) {
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
}
return notification;
}
示例3: showCzNotify
/**
* 显示常驻通知栏
*/
public void showCzNotify(String title, String content, String ticker, int notifyId) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
// //PendingIntent 跳转动作
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,Intent.getIntent(), 0);
mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setTicker(ticker)
.setContentTitle(title)
.setContentText(content);
// .setContentIntent(pendingIntent);
Notification mNotification = mBuilder.build();
//设置通知 消息 图标
mNotification.icon = R.mipmap.ic_launcher;
//在通知栏上点击此通知后自动清除此通知
mNotification.flags = Notification.FLAG_ONGOING_EVENT;//FLAG_ONGOING_EVENT 在顶部常驻,可以调用下面的清除方法去除 FLAG_AUTO_CANCEL 点击和清理可以去调
//设置显示通知时的默认的发声、震动、Light效果
mNotification.defaults = Notification.DEFAULT_VIBRATE;
//设置发出消息的内容
// mNotification.tickerText = "通知来了";
//设置发出通知的时间
mNotification.when = System.currentTimeMillis();
// mNotification.flags = Notification.FLAG_AUTO_CANCEL; //在通知栏上点击此通知后自动清除此通知
// mNotification.setLatestEventInfo(this, "常驻测试", "使用cancel()方法才可以把我去掉哦", null); //设置详细的信息 ,这个方法现在已经不用了
mNotificationManager.notify(notifyId, mNotification);
}
示例4: onBackground
private void onBackground(boolean flag) {
if (flag /*&& voiceMediator.isWakeUpMode()*/) {
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.wake_notification);
Intent resultIntent = new Intent(AssistantService.this, MainActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), ServiceCmd.PLAY_IN_BACKGROUND, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentIntent(resultPendingIntent);
mBuilder.setAutoCancel(false);
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setContent(remoteViews);
Notification nf = mBuilder.build();
nf.flags = Notification.FLAG_ONGOING_EVENT;
startForeground(1, nf);
} else {
stopForeground(true);
}
}
示例5: onStartCommand
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
int result = super.onStartCommand(intent, flags, startId);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if (intent != null && intent.getAction() != null && intent.getAction().equals("stop")) {
// User clicked the notification. Need to stop the service.
nm.cancel(0);
stopSelf();
} else {
// Service starting. Create a notification.
Notification notification =
new Notification.Builder(getApplicationContext())
.setContentTitle("CommunicationService")
.setContentText("Connected! click to stop.")
.build();
notification.flags |= Notification.FLAG_ONGOING_EVENT;
nm.notify(0, notification);
//showToast(notification.category);
}
return result;
}
示例6: initNotification
/**
* 初始化Notification,此处做Notification的基本设置
*/
private void initNotification(){
try{//解决崩溃问题
PendingIntent contentPendingIntent = createPendingIntent(mContext,
SettingActivity.class);
//获取notification管理的实例
notificationManager = (NotificationManager) this.mContext.getSystemService(Context.NOTIFICATION_SERVICE);
createNotification();
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.contentIntent = contentPendingIntent;
}catch(Exception ex){
ex.printStackTrace();
}catch(Throwable e){
e.printStackTrace();
}
}
示例7: Notify
public void Notify() {
if(checkNotify()) {
Date date = new Date();
String time = String.format("%tY%tm%td", date, date, date);
Cursor cursor_total = dbmanager.openDatabase().rawQuery("select sum(heat) as total from diet where time=?", new String[] { time });
cursor_total.moveToFirst();
String total = String.format("%.0f", cursor_total.getDouble(0)) + "��";
//����֪ͨ��չ�ֵ�������Ϣ
Notification notification = new Notification(R.drawable.ic_launcher, "��������������:" + total, System.currentTimeMillis());
notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
int i = (int)(Math.random()*5);
notification.setLatestEventInfo(this, "��������������:" + total, tips[i], contentIntent);
mNotificationManager.notify(1, notification);
}
}
示例8: notifyDownloadStart
/**
* 开始下载
*
* @param context
* @param title
* @param icon
*/
private void notifyDownloadStart(Context context, Request request)
{
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.api_download_notification);
remoteViews.setProgressBar(R.id.noti_progressBar, PROGRESSBAR_MAX, 0, false);
remoteViews.setImageViewResource(R.id.noti_icon, R.drawable.notification_remote_icon);
remoteViews.setTextViewText(R.id.noti_file_name, request.mTitle);
String host = CommonUtils.getHost(request.mDownloadUrl);
if (CommonUtils.isWo2bHost(request.mDownloadUrl))
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, "www.wo2b.com");
}
else
{
remoteViews.setTextViewText(R.id.noti_progressBarLeft, host);
}
// 执行取消操作的PendingIntent, 向DownloadService发起取消下载的命令
Intent cancelIntent = new Intent();
cancelIntent.setClass(context, DownloadService.class);
cancelIntent.putExtra(DownloadService.EXTRA_EVENT_TYPE, DownloadService.EVENT_CANCEL);
cancelIntent.putExtra(DownloadService.EXTRA_DOWNLOAD_URL, request.mDownloadUrl);
PendingIntent cancelPendingIntent = PendingIntent.getService(context, 100, cancelIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.noti_cancel, cancelPendingIntent);
// 消息信息设置
Notification notification = new Notification();
notification.tickerText = request.mTitle;
notification.icon = R.drawable.notification_icon;
notification.contentView = remoteViews;
// notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.flags = Notification.FLAG_ONGOING_EVENT;
// 点击通知栏
Intent intent = new Intent();
intent.setAction("com.wo2b.download.AActivity");
// intent.setClass(context, Download.class);
notification.contentIntent = PendingIntent.getActivity(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// 生成通知ID
int notificationId = new Random().nextInt(10000);
mNotificationManager.notify(notificationId, notification);
request.mNotification = notification;
request.mNotificationId = notificationId;
}
示例9: onCreateMusicNotification
/**
* 初始化自定义通知
*/
public void onCreateMusicNotification(){
Log.e(TAG,"初始化MusicNotification对象");
//注册点击事件
//1.播放事件
playIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_PLAY);
PendingIntent pendingPlayIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,playIntent,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.img_play,pendingPlayIntent);
//2.下一首事件
nextIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_NEXT);
PendingIntent pendingNextIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,nextIntent,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.img_next,pendingNextIntent);
//3.关闭通知事件
closeIntent.putExtra("type",MUSIC_NOTIFICATION_VALUE_CLOSE);
PendingIntent pendingCloseIntent = PendingIntent.getBroadcast(context,REQUEST_CODE,closeIntent,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.img_close,pendingCloseIntent);
//4.点击通知返回App
PendingIntent pendingBackIntent = PendingIntent.getActivity(MyApplication.mContext,REQUEST_CODE,backIntent,PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.notification_contanier,pendingBackIntent);
builder.setContent(remoteViews)
.setOngoing(true)//表示正在运行的通知,常用于音乐播放或者文件下载
.setSmallIcon(R.mipmap.notification_img_holder);
notification = builder.build();
notification.flags = Notification.FLAG_ONGOING_EVENT;//将此通知放到通知栏的"Ongoing",“正在运行”组中
// notificationManager.notify(NOTIFICATION_ID,notification);//弹出通知
mService.startForeground(NOTIFICATION_ID,notification);
}
示例10: createInCallNotification
public static Notification createInCallNotification(Context context,
String title, String msg, int iconID, Bitmap contactIcon,
String contactName, PendingIntent intent) {
Notification notif = new Notification.Builder(context).setContentTitle(contactName)
.setContentText(msg).setSmallIcon(iconID)
.setAutoCancel(false)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon).build();
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif;
}
示例11: createNotification
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
Notification notif;
if (largeIcon != null) {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setLargeIcon(largeIcon)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setPriority(priority)
.build();
} else {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setPriority(priority)
.build();
}
if (isOngoingEvent) {
notif.flags |= Notification.FLAG_ONGOING_EVENT;
}
return notif;
}
示例12: createInCallNotification
@SuppressWarnings("deprecation")
public static Notification createInCallNotification(Context context,
String title, String msg, int iconID, Bitmap contactIcon,
String contactName, PendingIntent intent) {
Notification notif = new Notification.Builder(context).setContentTitle(contactName)
.setContentText(msg).setSmallIcon(iconID)
.setAutoCancel(false)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon).getNotification();
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif;
}
示例13: createNotification
@SuppressWarnings("deprecation")
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
Notification notif;
if (largeIcon != null) {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setLargeIcon(largeIcon)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.getNotification();
} else {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.getNotification();
}
if (isOngoingEvent) {
notif.flags |= Notification.FLAG_ONGOING_EVENT;
}
return notif;
}
示例14: initNotification
@Override
public void initNotification(Context context) {
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
remoteViews = new RemoteViews(context.getPackageName(), R.layout.music_notification);
Intent intent1 = new Intent(context.getApplicationContext(), AssistantService.class);
intent1.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.TOGGLE_PLAY);
PendingIntent pi1 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.TOGGLE_PLAY, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.notice_switch, pi1);
Intent intent2 = new Intent(context.getApplicationContext(), AssistantService.class);
intent2.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.NEXT_MUSIC);
PendingIntent pi2 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.NEXT_MUSIC, intent2, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.notice_next, pi2);
Intent intent3 = new Intent(context.getApplicationContext(), AssistantService.class);
intent3.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.CLOSE_PLAY_NOTIFICATION);
PendingIntent pi3 = PendingIntent.getService(context.getApplicationContext(), AssistantService.ServiceCmd.CLOSE_PLAY_NOTIFICATION, intent3, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.notice_close, pi3);
/* 点击通知栏进入主界面 */
Intent intent4 = new Intent(context.getApplicationContext(), MainActivity.class);
PendingIntent pi4 = PendingIntent.getActivity(context.getApplicationContext(), 0, intent4, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setAutoCancel(false);
mBuilder.setSmallIcon(R.drawable.ic_launcher);
mBuilder.setContent(remoteViews);
notification = mBuilder.build();
notification.contentIntent = pi4;
// notification.flags = Notification.FLAG_NO_CLEAR; // 点击清除按钮时就会清除消息通知,但是点击通知栏的通知时不会消失
notification.flags = Notification.FLAG_ONGOING_EVENT; // 点击清除按钮不会清除消息通知,可以用来表示在正在运行
}
示例15: lavNotification
@SuppressLint("NewApi")
public static Notification lavNotification(Context ctx) {
String kanalNavn = App.afspiller.getLydkilde().getKanal().navn;
NotificationCompat.Builder b = new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.dr_notifikation)
.setContentTitle(ctx.getString(R.string.appnavn))
.setContentText(kanalNavn)
.setOngoing(true)
.setAutoCancel(false)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(1001) // holder den øverst
.setContentIntent(PendingIntent.getActivity(ctx, 0, new Intent(ctx, Hovedaktivitet.class), 0));
// PendingIntent er til at pege på aktiviteten der skal startes hvis
// brugeren vælger notifikationen
b.setContent(AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_lille));
Notification notification = b.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// A notification's big view appears only when the notification is expanded,
// which happens when the notification is at the top of the notification drawer,
// or when the user expands the notification with a gesture.
// Expanded notifications are available starting with Android 4.1.
notification.bigContentView = AfspillerIkonOgNotifikation.lavRemoteViews(AfspillerIkonOgNotifikation.TYPE_notifikation_stor);
}
notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT | Notification.PRIORITY_HIGH | Notification.FLAG_FOREGROUND_SERVICE);
return notification;
}