您的位置:首页 > 移动开发 > Android开发

Android中添加常驻通知栏

2015-10-10 17:47 501 查看
直接看代码吧,很简单的小功能,核心代码就是设置notification的flags为Notification.FLAG_ONGOING_EVENT

// 添加常驻通知

private void setNotification() {

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

Notification notification = new Notification(R.drawable.ic_launcher,

getString(R.string.app_name), System.currentTimeMillis());

Intent intent = new Intent(this, Rcp_birthdayActivity.class);

notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻 Flag

PendingIntent contextIntent = PendingIntent.getActivity(this, 0,

intent, 0);

notification.setLatestEventInfo(getApplicationContext(),

getString(R.string.app_name), "点击查看", contextIntent);

notificationManager.notify(R.string.app_name, notification);

}

// 取消通知

private void cancelNotification() {

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.cancel(R.string.app_name);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: