Java Code Examples for android.app.Notification#VISIBILITY_PUBLIC
The following examples show how to use
android.app.Notification#VISIBILITY_PUBLIC .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RankingHelper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void createNotificationChannel(String pkg, int uid, NotificationChannel channel, boolean fromTargetApp, boolean hasDndAccess) { Preconditions.checkNotNull(pkg); Preconditions.checkNotNull(channel); Preconditions.checkNotNull(channel.getId()); Preconditions.checkArgument(!TextUtils.isEmpty(channel.getName())); Record r = getOrCreateRecord(pkg, uid); if (r == null) { throw new IllegalArgumentException("Invalid package"); } if (channel.getGroup() != null && !r.groups.containsKey(channel.getGroup())) { throw new IllegalArgumentException("NotificationChannelGroup doesn't exist"); } if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(channel.getId())) { throw new IllegalArgumentException("Reserved id"); } NotificationChannel existing = r.channels.get(channel.getId()); // Keep most of the existing settings if (existing != null && fromTargetApp) { if (existing.isDeleted()) { existing.setDeleted(false); // log a resurrected channel as if it's new again MetricsLogger.action(getChannelLog(channel, pkg).setType( MetricsProto.MetricsEvent.TYPE_OPEN)); } existing.setName(channel.getName().toString()); existing.setDescription(channel.getDescription()); existing.setBlockableSystem(channel.isBlockableSystem()); if (existing.getGroup() == null) { existing.setGroup(channel.getGroup()); } // Apps are allowed to downgrade channel importance if the user has not changed any // fields on this channel yet. if (existing.getUserLockedFields() == 0 && channel.getImportance() < existing.getImportance()) { existing.setImportance(channel.getImportance()); } // system apps and dnd access apps can bypass dnd if the user hasn't changed any // fields on the channel yet if (existing.getUserLockedFields() == 0 && hasDndAccess) { boolean bypassDnd = channel.canBypassDnd(); existing.setBypassDnd(bypassDnd); if (bypassDnd != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(); } } updateConfig(); return; } if (channel.getImportance() < IMPORTANCE_NONE || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { throw new IllegalArgumentException("Invalid importance level"); } // Reset fields that apps aren't allowed to set. if (fromTargetApp && !hasDndAccess) { channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); } if (fromTargetApp) { channel.setLockscreenVisibility(r.visibility); } clearLockedFields(channel); if (channel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { channel.setLockscreenVisibility(Ranking.VISIBILITY_NO_OVERRIDE); } if (!r.showBadge) { channel.setShowBadge(false); } r.channels.put(channel.getId(), channel); if (channel.canBypassDnd() != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(); } MetricsLogger.action(getChannelLog(channel, pkg).setType( MetricsProto.MetricsEvent.TYPE_OPEN)); }
Example 2
Source File: RankingHelper.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@Override public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel, boolean fromUser) { Preconditions.checkNotNull(updatedChannel); Preconditions.checkNotNull(updatedChannel.getId()); Record r = getOrCreateRecord(pkg, uid); if (r == null) { throw new IllegalArgumentException("Invalid package"); } NotificationChannel channel = r.channels.get(updatedChannel.getId()); if (channel == null || channel.isDeleted()) { throw new IllegalArgumentException("Channel does not exist"); } if (updatedChannel.getLockscreenVisibility() == Notification.VISIBILITY_PUBLIC) { updatedChannel.setLockscreenVisibility(Ranking.VISIBILITY_NO_OVERRIDE); } if (!fromUser) { updatedChannel.unlockFields(updatedChannel.getUserLockedFields()); } if (fromUser) { updatedChannel.lockFields(channel.getUserLockedFields()); lockFieldsForUpdate(channel, updatedChannel); } r.channels.put(updatedChannel.getId(), updatedChannel); if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(updatedChannel.getId())) { // copy settings to app level so they are inherited by new channels // when the app migrates r.importance = updatedChannel.getImportance(); r.priority = updatedChannel.canBypassDnd() ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT; r.visibility = updatedChannel.getLockscreenVisibility(); r.showBadge = updatedChannel.canShowBadge(); } if (!channel.equals(updatedChannel)) { // only log if there are real changes MetricsLogger.action(getChannelLog(updatedChannel, pkg)); } if (updatedChannel.canBypassDnd() != mAreChannelsBypassingDnd) { updateChannelsBypassingDnd(); } updateConfig(); }
Example 3
Source File: CaptchaDecoratorService.java From nevo-decorators-sms-captchas with GNU General Public License v3.0 | 5 votes |
@Override protected void apply(MutableStatusBarNotification evolving) { MutableNotification notification = evolving.getNotification(); Bundle extras = notification.extras; boolean recast = extras.getBoolean(NOTIFICATION_EXTRA_RECAST, false); NotificationUtils.Messages messages = NotificationUtils.parseMessages(notification); String[] captchas = mCaptchaUtils.findSmsCaptchas(messages.texts); if (captchas.length == 0) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) notification.setChannelId(recast ? NOTIFICATION_CHANNEL_CAPTCHA_SILENT : NOTIFICATION_CHANNEL_CAPTCHA_NORMAL); else notification.priority = recast ? Notification.PRIORITY_LOW : Notification.PRIORITY_HIGH; KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); if (mSettings.isCaptchaHideOnLocked() && keyguardManager != null && keyguardManager.isKeyguardLocked()) applyKeyguardLocked(notification, evolving.getKey(), messages, captchas); else applyKeyguardUnlocked(notification, evolving.getKey(), messages, captchas); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; notification.visibility = Notification.VISIBILITY_PUBLIC; extras.putBoolean(Global.NOTIFICATION_EXTRA_APPLIED, true); mAppliedKeys.add(evolving.getKey()); Log.i(TAG, "Applied " + evolving.getKey()); }
Example 4
Source File: OdysseyNotificationManager.java From odyssey with GNU General Public License v3.0 | 5 votes |
public void hideMediaOnLockscreen(boolean enable) { mHideMediaOnLockscreen = enable; if (mNotification != null) { mNotification.visibility = mHideMediaOnLockscreen ? Notification.VISIBILITY_PRIVATE : Notification.VISIBILITY_PUBLIC; if (mNotificationManager != null) { mNotificationManager.notify(NOTIFICATION_ID, mNotification); } } }
Example 5
Source File: LeanplumNotificationChannel.java From Leanplum-Android-SDK with Apache License 2.0 | 4 votes |
NotificationChannelData(Map<String, Object> channel) { id = (String) channel.get("id"); name = (String) channel.get("name"); description = (String) channel.get("description"); groupId = (String) channel.get("groupId"); importance = (int) CollectionUtil.getOrDefault(channel, "importance", importance); enableLights = (boolean) CollectionUtil.getOrDefault(channel, "enable_lights", enableLights); lightColor = (int) CollectionUtil.getOrDefault(channel, "light_color", lightColor); enableVibration = (boolean) CollectionUtil.getOrDefault(channel, "enable_vibration", enableVibration); lockscreenVisibility = (int) CollectionUtil.getOrDefault(channel, "lockscreen_visibility", lockscreenVisibility); bypassDnd = (boolean) CollectionUtil.getOrDefault(channel, "bypass_dnd", bypassDnd); showBadge = (boolean) CollectionUtil.getOrDefault(channel, "show_badge", showBadge); try { List<Number> pattern = CollectionUtil.uncheckedCast( CollectionUtil.getOrDefault(channel, "vibration_pattern", null)); if (pattern != null) { vibrationPattern = new long[pattern.size()]; Iterator<Number> iterator = pattern.iterator(); for (int i = 0; i < vibrationPattern.length; i++) { Number next = iterator.next(); if (next != null) { vibrationPattern[i] = next.longValue(); } } } } catch (Exception e) { Log.w("Failed to parse vibration pattern."); } // Sanity checks. if (importance < NotificationManager.IMPORTANCE_NONE && importance > NotificationManager.IMPORTANCE_MAX) { importance = NotificationManager.IMPORTANCE_DEFAULT; } if (lockscreenVisibility < Notification.VISIBILITY_SECRET && lockscreenVisibility > Notification.VISIBILITY_PUBLIC) { lockscreenVisibility = Notification.VISIBILITY_PUBLIC; } }
Example 6
Source File: MainActivity.java From NotificationDemo with Apache License 2.0 | 4 votes |
@Override public void onClick(View v) { switch (v.getId()) { case R.id.switch_only_alert_once: mBuilder.setOnlyAlertOnce(binding.switchOnlyAlertOnce.isChecked()); break; case R.id.switch_auto_cancel: mBuilder.setAutoCancel(binding.switchAutoCancel.isChecked()); break; case R.id.switch_ongoing: mBuilder.setOngoing(binding.switchOngoing.isChecked()); break; case R.id.switch_info: mBuilder.setContentInfo("info"); break; case R.id.switch_public: if (binding.switchPublic.isChecked()) { mBuilder.setPublicVersion(NotifyUtil.create(this, R.mipmap.ic_wazhi, "public title", "public content.").build()); } else { mBuilder.setPublicVersion(null); } break; case R.id.switch_large_icon: if (binding.switchLargeIcon.isChecked()) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.large_icon); mBuilder.setLargeIcon(bitmap); } else { mBuilder.setLargeIcon(null); } break; case R.id.switch_ticker: if (binding.switchTicker.isChecked()) { mBuilder.setTicker("this is ticker"); } else { mBuilder.setTicker(null); } break; case R.id.switch_sub: if (binding.switchSub.isChecked()) { mBuilder.setSubText("his is sub"); } else { mBuilder.setSubText(null); } break; case R.id.switch_content_intent: if (binding.switchContentIntent.isChecked()) { mBuilder.setContentIntent(pi(2000)); } else { mBuilder.setContentIntent(null); mBuilder.mNotification.contentIntent = null; } break; case R.id.switch_delete_intent: if (binding.switchDeleteIntent.isChecked()) { mBuilder.setDeleteIntent(pi(2001)); } else { mBuilder.setDeleteIntent(null); mBuilder.mNotification.deleteIntent = null; } break; case R.id.switch_full_screen_intent: if (binding.switchFullScreenIntent.isChecked()) { mBuilder.setFullScreenIntent(pi(2002), true); } else { mBuilder.setFullScreenIntent(null, false); mBuilder.mNotification.fullScreenIntent = null; } break; case R.id.clear_all: NotifyUtil.cancelAll(this); break; case R.id.clear: NotifyUtil.cancel(this, mNotifyId); break; case R.id.send: mNotifyId++; final Notification notification = mBuilder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (notification.publicVersion != null && notification.visibility == Notification.VISIBILITY_PUBLIC) { binding.getRoot().postDelayed(new Runnable() { @Override public void run() { NotifyUtil.notify(mBuilder.mContext, mNotifyId, notification); } }, 5000); break; } } if (binding.switchInsistent.isChecked()) { notification.flags |= Notification.FLAG_INSISTENT; } if (binding.switchNoClear.isChecked()) { notification.flags |= Notification.FLAG_NO_CLEAR; } NotifyUtil.notify(this, mNotifyId, notification); break; } }