下面列出了android.app.Notification#DEFAULT_ALL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setNotificationSoundAndVibrate(NotificationCompat.Builder notificationBuilder, Message message) {
int notificationDefaults = Notification.DEFAULT_ALL;
if (!message.isVibrate()) {
notificationDefaults &= ~Notification.DEFAULT_VIBRATE;
} else if (ContextCompat.checkSelfPermission(context, Manifest.permission.VIBRATE) == PackageManager.PERMISSION_DENIED) {
notificationDefaults &= ~Notification.DEFAULT_VIBRATE;
MobileMessagingLogger.e("Unable to vibrate", new ConfigurationException(ConfigurationException.Reason.MISSING_REQUIRED_PERMISSION, Manifest.permission.VIBRATE));
}
if (!message.isDefaultSound()) {
notificationDefaults &= ~Notification.DEFAULT_SOUND;
}
notificationBuilder.setDefaults(notificationDefaults);
String sound = message.getSound();
if (message.isDefaultSound() || StringUtils.isBlank(sound)) {
return;
}
Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/raw/" + sound);
if (soundUri == null) {
MobileMessagingLogger.e("Cannot create uri for sound:" + sound + " messageId:" + message.getMessageId());
return;
}
notificationBuilder.setSound(soundUri);
}
private static void sendChatNotificationEvent(Context context, Intent intent, NotificationEvent notificationEvent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannelIfNotExist(notificationManager);
}
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_ONE_ID)
.setSmallIcon(getNotificationIcon())
.setContentTitle(notificationEvent.getTitle())
.setColor(context.getResources().getColor(R.color.accent))
.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationEvent.getSubject()))
.setContentText(notificationEvent.getBody())
.setAutoCancel(true)
.setContentIntent(contentIntent);
Notification notification = builder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
notificationManager.notify(NOTIFICATION_ID, notification);
}
public void apply(Notification notification) {
notification.defaults = 0;
if (isOff()) {
notification.defaults = 0;
} else if (isDefault()) {
notification.defaults = Notification.DEFAULT_ALL;
enableLights(notification);
} else {
applySound(notification);
applyVibration(notification);
applyLed(notification);
}
}
private void applyNotificationOptions(Notification notification, String notificationOptions) {
if (notificationOptions == null) {
notification.defaults = Notification.DEFAULT_ALL;
} else {
NotificationOptions options = NotificationOptions.parse(notificationOptions);
options.apply(notification);
}
}
public void init(Context context) {
this.context = context;
this.nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
int defaults = Notification.DEFAULT_ALL
| Notification.FLAG_AUTO_CANCEL;
this.defaults = defaults;
}
public void onReceive(Context context, Intent intent) {
SharedPreferences shareDate =
context.getSharedPreferences("timing",Activity.MODE_PRIVATE);
int date = shareDate.getInt("date",1);
String str = getNowDate(context, date);
boolean flag = matchRecode(context, str);
Log.v("test_dick",flag+"");
if(flag){
//context.startService(new Intent(context, cn.scau.scautreasure.service.NotificationService.class));
try {
NotificationManager mNotificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
int notificationIcon= R.drawable.icon;
CharSequence notificationTitle="来自华农宝";
long when = System.currentTimeMillis();
Notification notification=new Notification(notificationIcon, notificationTitle, when);
notification.defaults=Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intentservice=new Intent(context.getApplicationContext(), BorrowedBook_.class);
PendingIntent pendingIntent=PendingIntent.getActivity(context.getApplicationContext(), 0, intentservice, 0);
notification.setLatestEventInfo(context.getApplicationContext(),"借阅到期提示", "你有N本书即将满借阅",pendingIntent);
mNotificationManager.notify(1000, notification);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@SuppressWarnings("deprecation")
@Override
public int onStartCommand(Intent intent,int flags,int startId)
{
super.onStart(intent, startId);
try {
NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int notificationIcon= R.drawable.icon;
CharSequence notificationTitle="来自华农宝";
long when = System.currentTimeMillis();
Notification notification=new Notification(notificationIcon, notificationTitle, when);
notification.defaults=Notification.DEFAULT_ALL;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intentservice=new Intent(getApplicationContext(), BorrowedBook_.class);
PendingIntent pendingIntent=PendingIntent.getActivity(getApplicationContext(), 0, intentservice, 0);
notification.setLatestEventInfo(getApplicationContext(),"借阅到期提示", "你有N本书即将满借阅",pendingIntent);
mNotificationManager.notify(1000, notification);
} catch (Exception e) {
e.printStackTrace();
}
return Service.START_CONTINUATION_MASK;
}
@Override
public int value()
{
return Notification.DEFAULT_ALL;
}