本文整理汇总了Java中android.app.Notification.FLAG_INSISTENT属性的典型用法代码示例。如果您正苦于以下问题:Java Notification.FLAG_INSISTENT属性的具体用法?Java Notification.FLAG_INSISTENT怎么用?Java Notification.FLAG_INSISTENT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.app.Notification
的用法示例。
在下文中一共展示了Notification.FLAG_INSISTENT属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleTriggerAlarm
private void handleTriggerAlarm(Intent i) {
final long alarmid = i.getLongExtra(ALARM_ID, -1);
final DbUtil.Settings settings =
DbUtil.Settings.get(getApplicationContext(), alarmid);
PowerManager.WakeLock w = null;
if (i.hasExtra(AlarmTriggerReceiver.WAKELOCK_ID)) {
w = AlarmTriggerReceiver.consumeLock(
i.getExtras().getInt(AlarmTriggerReceiver.WAKELOCK_ID));
}
if (w == null)
Log.e(TAG, "No wake lock present for alarm trigger " + alarmid);
if (activeAlarms == null) {
activeAlarms = new ActiveAlarms(getApplicationContext(), w, settings);
} else {
Log.i(TAG, "Already wake-locked, releasing extra lock");
w.release();
}
activeAlarms.alarmids.add(alarmid);
String labels = "";
for (long id : activeAlarms.alarmids) {
String label = DbUtil.Alarm.get(getApplicationContext(), id).label;
if (!label.isEmpty()) {
if (labels.isEmpty())
labels = label;
else
labels += ", " + label;
}
}
Intent notify = new Intent(this, AlarmNotificationActivity.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(ALARM_ID, alarmid);
final Notification notification =
new Notification.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setContentText(labels.isEmpty() ? getString(R.string.dismiss) : labels)
.setSmallIcon(R.drawable.ic_alarm_on)
.setContentIntent(PendingIntent.getActivity(this, 0, notify, 0))
.setCategory(Notification.CATEGORY_ALARM)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setOngoing(true)
.setLights(Color.WHITE, 1000, 1000)
.setVibrate(settings.vibrate ? new long[] {1000, 1000} : null)
.build();
notification.flags |= Notification.FLAG_INSISTENT; // Loop sound/vib/blink
startForeground(FIRING_ALARM_NOTIFICATION_ID, notification);
refreshNotifyBar();
startActivity(notify);
}
示例2: previewSettings
private void previewSettings() {
Notification.Builder builder = new Notification.Builder(this)
.setContentTitle(getString(R.string.lc_preview_notif_title))
.setContentText(String.format(Locale.getDefault(),
getString(R.string.lc_preview_notif_text), getTitle()))
.setSmallIcon(R.drawable.ic_notif_gravitybox)
.setLargeIcon(Icon.createWithResource(this, R.drawable.ic_launcher));
final Notification n = builder.build();
if (mPrefsFragment.getLedMode() == LedMode.OFF) {
n.defaults &= ~Notification.DEFAULT_LIGHTS;
n.flags &= ~Notification.FLAG_SHOW_LIGHTS;
} else if (mPrefsFragment.getLedMode() == LedMode.OVERRIDE) {
n.defaults &= ~Notification.DEFAULT_LIGHTS;
n.flags |= Notification.FLAG_SHOW_LIGHTS;
n.ledARGB = mPrefsFragment.getColor();
n.ledOnMS = mPrefsFragment.getLedOnMs();
n.ledOffMS = mPrefsFragment.getLedOffMs();
}
if (mPrefsFragment.getSoundOverride() && mPrefsFragment.getSoundUri() != null) {
n.defaults &= ~Notification.DEFAULT_SOUND;
n.sound = mPrefsFragment.getSoundUri();
}
if (mPrefsFragment.getInsistent()) {
n.flags |= Notification.FLAG_INSISTENT;
}
if (mPrefsFragment.getVibrateOverride()) {
try {
long[] pattern = LedSettings.parseVibratePatternString(
mPrefsFragment.getVibratePatternAsString());
n.defaults &= ~Notification.DEFAULT_VIBRATE;
n.vibrate = pattern;
} catch (Exception e) {
Toast.makeText(this, getString(R.string.lc_vibrate_pattern_invalid),
Toast.LENGTH_SHORT).show();
}
}
if (mPrefsFragment.getVisibility() != Visibility.DEFAULT) {
n.visibility = mPrefsFragment.getVisibility().getValue();
}
if (mPrefsFragment.getVisibilityLs() != VisibilityLs.DEFAULT) {
n.extras.putString(ModLedControl.NOTIF_EXTRA_VISIBILITY_LS,
mPrefsFragment.getVisibilityLs().toString());
}
n.extras.putBoolean("gbIgnoreNotification", true);
Intent intent = new Intent(ModHwKeys.ACTION_SLEEP);
sendBroadcast(intent);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(++NOTIF_ID, n);
}
}, 1000);
}