本文整理汇总了Java中android.app.Notification.FLAG_NO_CLEAR属性的典型用法代码示例。如果您正苦于以下问题:Java Notification.FLAG_NO_CLEAR属性的具体用法?Java Notification.FLAG_NO_CLEAR怎么用?Java Notification.FLAG_NO_CLEAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.FLAG_NO_CLEAR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notificationMethod
private Notification notificationMethod() {
Notification notification;
PendingIntent pendingIntent = PendingIntent.getService(this, 0, new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SHOW), 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getClass().getSimpleName())
.setContentTitle("当前应用包名,点击查看详细")
.setContentText(currentActivity.getCurrentActivity())
.setContentIntent(pendingIntent)
.setSmallIcon(R.mipmap.ic_launcher);
Intent exitIntent = new Intent(this, FloatViewService.class).setAction(ACTION_FLOAT_VIEW_SERVICE_STOP);
builder.addAction(R.drawable.ic_action_exit, getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));
notification = builder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
return notification;
}
示例2: 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);
}
}
示例3: buildCallingNotification
private void buildCallingNotification() {
if (callingNotification == null) {
Intent localIntent = new Intent();
localIntent.setClass(context, TeamAVChatActivity.class);
localIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
String tickerText = String.format(context.getString(R.string.avchat_notification), displayName);
int iconId = R.drawable.ic_stat_notify_msg;
PendingIntent pendingIntent = PendingIntent.getActivity(context, CALLING_NOTIFY_ID, localIntent, PendingIntent
.FLAG_UPDATE_CURRENT);
callingNotification = makeNotification(pendingIntent, context.getString(R.string.avchat_call), tickerText, tickerText,
iconId, false, false);
callingNotification.flags |= Notification.FLAG_NO_CLEAR;
}
}
示例4: 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;
}
示例5: onStop
@Override
protected void onStop() {
super.onStop();
GoogleAnalyticsManager.getInstance().activityStop(this);
//do not create notification if back pressed (or it is not recording?)
//or if activity was not launched
if(mLaunchActivity && !backPressed) {
Intent resultIntent = new Intent(this, AudioRecorderActivity.class);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//bring existing activity to foreground
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT //update existing notification instead of creating new one
);
if(mIsRecording)
mBuilder.setLargeIcon(notificationLargeIconBitmapRecordingOn);
else
mBuilder.setLargeIcon(notificationLargeIconBitmapRecordingOff);
mBuilder.setContentIntent(resultPendingIntent);
Notification notification = mBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;//the notification should disappear when it is clicked by the user.
notification.flags |= Notification.FLAG_NO_CLEAR;//the notification should not be removed when the user clicks the Clear all button.
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(NOTIFICATION_ID, notification);
}
}
示例6: updateNotification
public static void updateNotification(Context context) {
ConnectionStatus status = connectionEngine.getConnectionStatus();
Notification.Builder builder = new Notification.Builder(context);
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
builder.setContentIntent(pendingIntent);
int iconId = R.drawable.ic_stat_discon;
String msg = "RepWifi";
if (status != null) {
if (status.isConnected()) {
iconId = R.drawable.ic_stat_repwifi;
msg += " - " + status.SSID;
} else {
msg += " - " + status.status;
}
}
builder.setSmallIcon(iconId);
builder.setContentTitle(msg);
builder.setContentText("Touch to open.");
Notification n = builder.build();
n.flags |= Notification.FLAG_NO_CLEAR;
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Service.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, n);
}
示例7: keepAlive
private void keepAlive() {
try {
Notification notification = new Notification();
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(0, notification); // 设置为前台服务避免kill,Android4.3及以上需要设置id为0时通知栏才不显示该通知;
} catch (Throwable e) {
e.printStackTrace();
}
}
示例8: processSubscriptionRequest
private void processSubscriptionRequest(Bundle data) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
long pubId = preferences.getLong(MobileClient.PUBLISHER_ID, 0);
// The id must be parsed, as it is in fact a String
long subId = Long.parseLong(data.getString(SUBSCRIBER_ID));
String subUsername = data.getString(SUBSCRIBER_USERNAME);
int notificationId = 1;
// Pending Intent for the Reject action
PendingIntent rejectPendingIntent = createPendingIntentForActions(
NotificationProcessorReceiver.ACTION_REJECT, pubId, subId, subUsername, notificationId);
// Pending Intent for the Accept action
PendingIntent acceptPendingIntent = createPendingIntentForActions(
NotificationProcessorReceiver.ACTION_ACCEPT, pubId, subId, subUsername, notificationId);
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("MAGPIE Notification")
.setContentText("Subscription request from " + subUsername)
.addAction(R.drawable.abc_ic_clear_material, "Reject", rejectPendingIntent)
.addAction(R.drawable.ic_done_black_24dp, "Accept", acceptPendingIntent);
Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notification);
}
示例9: showToDoNotification
public static void showToDoNotification(Context context, long toDoID, String notificationTitle, String notificationText, int triggeredBy, String carUOMCode, String minutesOrDays) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
ToDoNotificationBuilder toDoNotificationBuilder =
new ToDoNotificationBuilder(context, notificationManager, toDoID, notificationTitle, notificationText, triggeredBy, carUOMCode, minutesOrDays);
// Gets an instance of the NotificationManager service
// Builds the notification and issues it.
Notification n = toDoNotificationBuilder.build();
n.flags |= Notification.FLAG_NO_CLEAR;
if (notificationManager != null) {
notificationManager.notify(((Long) toDoID).intValue(), n);
}
}
示例10: 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;
}
示例11: onCreate
@Override
public void onCreate() {
log.d("onCreate");
super.onCreate();
noteMng = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new
NotificationCompat.Builder(this);
builder.setTicker("Hello RemotesViews!");// 收到通知的时候用于显示于屏幕顶部通知栏的内容
builder.setSmallIcon(R.drawable.ic_notify);// 设置通知小图标,在下拉之前显示的图标
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_notify));// 落下后显示的图标
builder.setWhen(System.currentTimeMillis());
// builder.setOngoing(true);// 不能被用户x掉,会一直显示,如音乐播放等
// builder.setAutoCancel(true);// 自动取消
// builder.setOnlyAlertOnce(true);// 只alert一次
// builder.setDefaults(Notification.DEFAULT_ALL);
// myNotify.icon=R.drawable.ic_notify;
// myNotify.tickerText = "";
// myNotify.when = System.currentTimeMillis();
//
RemoteViews rv = new RemoteViews(getPackageName(),
R.layout.notification);
builder.setCustomBigContentView(rv);
// myNotify.bigContentView=rv;
// myNotify.contentView =rv;
// rv.setOnClickPendingIntent();
Notification myNotify = builder.build();
myNotify.flags = Notification.FLAG_NO_CLEAR;// 不能够自动清除
PendingIntent piWeather=PendingIntent.getService(this, 0, new Intent(this, HeWeatherService.class), PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.btWeather,piWeather);
PendingIntent piVcard=PendingIntent.getService(this, 0, new Intent(this, VcardService.class), PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.btVcard,piVcard);
PendingIntent piSimInfo=PendingIntent.getService(this, 0, new Intent(this, SimService.class), PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.btSimInfo,piSimInfo);
Intent intent = new Intent(this,com.classic.clearprocesses.ForceStopActivity.class);//"com.classic.clearprocesses.ForceStopActivity");
// intent.setClassName("com.classic.clearprocesses", "com.classic.clearprocesses.ForceStopActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// this.startActivity(intent);
PendingIntent psProcee=PendingIntent.getActivity(this,0,intent, Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
rv.setOnClickPendingIntent(R.id.btStop,psProcee);
PendingIntent piJump=PendingIntent.getService(this, 0, new Intent(this, JumpService.class), PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.btJump,piJump);
//设置进度条,最大值 为100,当前值为0,最后一个参数为true时显示条纹
// myNotify.contentView.setProgressBar(R.id.pb, 100,0, false);
// myNotify.contentView.setProgressBar(R.id.pb, 100,50, false);
noteMng.notify(NOTIFICATION_FLAG, myNotify);
}
示例12: declareMinuteNotification
public void declareMinuteNotification() {
if (settingsprefs.getBoolean("shakeToExtend", false)) {
if (!shakeDetectionActive) {
startShakeDetection();
}
} else {
if (shakeDetectionActive) {
stopShakeDetection();
}
}
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Intent cancelIntent = new Intent(this, NotificationClickReceiver.class);
cancelIntent.putExtra("action", "cancel");
if (mode.equals("boot")) {
cancelIntent.putExtra("mode", "boot");
} else if (mode.equals("minute")) {
cancelIntent.putExtra("mode", "minute");
}
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 1, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent extendIntent = new Intent(this, NotificationClickReceiver.class);
extendIntent.putExtra("action", "extend");
if (mode.equals("boot")) {
extendIntent.putExtra("mode", "boot");
} else if (mode.equals("minute")) {
extendIntent.putExtra("mode", "minute");
}
PendingIntent pendingIntentExtend = PendingIntent.getBroadcast(this, 2, extendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.notification_icon).setTicker(getString(R.string.app_name)).setWhen(System.currentTimeMillis())
.setAutoCancel(false).setContentTitle(getString(R.string.app_name)).setOngoing(true)
.setContentText(getString(R.string.shutdownin) + counter)
.addAction(R.drawable.stop, getString(R.string.stop), pendingIntentCancel)
.addAction(R.drawable.addtime, getString(R.string.extend), pendingIntentExtend)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
nm.notify(1, notification);
}
示例13: declareTimeNotification
public void declareTimeNotification() {
if (settingsprefs.getBoolean("shakeToExtend", false)) {
if (!shakeDetectionActive) {
startShakeDetection();
}
} else {
if (shakeDetectionActive) {
stopShakeDetection();
}
}
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
Intent cancelIntent = new Intent(this, NotificationClickReceiver.class);
cancelIntent.putExtra("action", "cancel");
cancelIntent.putExtra("mode", "time");
PendingIntent pendingIntentCancel = PendingIntent.getBroadcast(this, 1, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent extendIntent = new Intent(this, NotificationClickReceiver.class);
extendIntent.putExtra("action", "extend");
extendIntent.putExtra("mode", "time");
PendingIntent pendingIntentExtend = PendingIntent.getBroadcast(this, 2, extendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar now = Calendar.getInstance();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(settingsprefs.getLong("timeShutdownTime", 0));
cal.set(Calendar.SECOND, 0);
String tomorrow = "";
if ((cal.get(Calendar.DATE) - now.get(Calendar.DATE)) == 1) {
tomorrow = getString(R.string.tomorrow);
}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.getDefault());
String time = sdf.format(cal.getTime());
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Notification notification = builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.notification_icon).setTicker(getString(R.string.app_name)).setWhen(System.currentTimeMillis())
.setAutoCancel(false).setContentTitle(getString(R.string.app_name)).setOngoing(true)
.setContentText(getString(R.string.shutdown) + " " + tomorrow + getString(R.string.at) + " " + time + " " + getString(R.string.uhr))
.addAction(R.drawable.stop, getString(R.string.stop), pendingIntentCancel)
.addAction(R.drawable.addtime, getString(R.string.extend), pendingIntentExtend)
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
nm.notify(1, notification);
}
示例14: notifyRegisteredAccounts
public synchronized void notifyRegisteredAccounts(ArrayList<SipProfileState> activeAccountsInfos, boolean showNumbers) {
if (!isServiceWrapper) {
Log.e(THIS_FILE, "Trying to create a service notification from outside the service");
return;
}
int icon = R.drawable.ic_stat_sipok;
CharSequence tickerText = context.getString(R.string.service_ticker_registered_text);
long when = System.currentTimeMillis();
Builder nb = new Builder(context);
nb.setSmallIcon(icon);
nb.setTicker(tickerText);
nb.setWhen(when);
Intent notificationIntent = new Intent(SipManager.ACTION_SIP_DIALER);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RegistrationNotification contentView = new RegistrationNotification(context.getPackageName());
contentView.clearRegistrations();
if(!Compatibility.isCompatible(9)) {
contentView.setTextsColor(notificationPrimaryTextColor);
}
contentView.addAccountInfos(context, activeAccountsInfos);
// notification.setLatestEventInfo(context, contentTitle,
// contentText, contentIntent);
nb.setOngoing(true);
nb.setOnlyAlertOnce(true);
nb.setContentIntent(contentIntent);
nb.setContent(contentView);
Notification notification = nb.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
// We have to re-write content view because getNotification setLatestEventInfo implicitly
notification.contentView = contentView;
if (showNumbers) {
// This only affects android 2.3 and lower
notification.number = activeAccountsInfos.size();
}
startForegroundCompat(REGISTER_NOTIF_ID, notification);
}
示例15: onStartCommand
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent openActivityIntent=new Intent(context, MainActivity.class);
openActivityIntent.putExtra("service_on",true);
openActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent openActivityPIntent = PendingIntent.getActivity(context, Constant.AUTO_REQUEST_CODE, openActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent stopAutoIntent = new Intent(context, StopAutoListenReceiver.class);
stopAutoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent stopAutoPIntent = PendingIntent.getBroadcast(context, Constant.REQUEST_CODE, stopAutoIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Icon icon = Icon.createWithResource(context,R.drawable.ic_stop_black_24dp);
Notification.Action.Builder builder = new Notification.Action.Builder(icon, "STOP", stopAutoPIntent);
vNotification = new Notification.Builder(context,GENERAL_CHANNEL)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(bitmap)
.setContentTitle("TwittaSave AutoListen Running...")
.setContentText("Copy tweet URL to start downloading video or gif")
.setContentIntent(openActivityPIntent)
.setAutoCancel(true)
.addAction(builder.build())
.build();
vNotification.flags=Notification.FLAG_NO_CLEAR;
notificationManager.notify(Constant.NOTI_IDENTIFIER, vNotification);
}else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
vNotification = new Notification.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(bitmap)
.setContentTitle("TwittaSave AutoListen Running...")
.setContentText("Copy tweet URL to start downloading video or gif")
.setContentIntent(openActivityPIntent)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_HIGH)
.addAction(R.drawable.ic_stop_black_24dp, "STOP", stopAutoPIntent)
.build();
vNotification.flags=Notification.FLAG_NO_CLEAR;
notificationManager.notify(Constant.NOTI_IDENTIFIER, vNotification);
}else{
vNotification1 = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(bitmap)
.setContentTitle("TwittaSave AutoListen Running...")
.setContentText("Copy tweet URL to start downloading video or gif")
.setContentIntent(openActivityPIntent)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
.setAutoCancel(true)
.addAction(R.drawable.ic_stop_black_24dp, "STOP", stopAutoPIntent);
notificationManager.notify(Constant.NOTI_IDENTIFIER, vNotification1.build());
}
mClipboard.addPrimaryClipChangedListener(listener);
Toast.makeText(context, "TwittaSave AutoListen Enabled", Toast.LENGTH_SHORT).show();
return super.onStartCommand(intent, flags, startId);
}