我想展示正在进行的通知。但它仍然出现在通知部分。 我使用自定义布局进行通知。
这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.alert_dark_frame;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, "Hi", when);
RemoteViews contentView = new RemoteViews(getPackageName(),
R.layout.custom_notification);
notification.contentView = contentView;
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.defaults |= Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(0, notification);
}
编辑: 你可以看到这张图片,看看我想做什么。 http://backcountrynavigator.com/wp-content/uploads/screenshots/download_ongoing_notification.png
答案 0 :(得分:0)
除了Service.startForeground()
NotificationManager.notify()
开始持续通知
编辑:我还建议你使用Notification.Builder而不是新的Notification(),然后使用setOngoing(),只是为了让它保持干净。