類似於音樂播放的, 常駐Notification
notification.flags = Notification.FLAG_ONGOING_EVENT;
private void normalStyleNotification() {
Intent intent = new Intent(AutoUpdateService.this, MainActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent =
PendingIntent.getActivity(AutoUpdateService.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(AutoUpdateService.this);
Notification notification = builder.setContentIntent(pendingIntent)
.setContentTitle("天氣")
.setContentText("當前溫度: %s℃")
// 這裏部分 ROM 無法成功
.setSmallIcon(R.mipmap.ic_launcher)
.build();
notification.flags = Notification.FLAG_ONGOING_EVENT;
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// tag和id都是可以拿來區分不同的通知的
manager.notify(1, notification);
}