Android的Notification简单实现方法
1、独立编写产生Notification 的方法private static int NOTIFICATION_ID=R.layout.main;
publicvoid GreateNotification (){
NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.sun, "天气预报", System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 1, new Intent(), 1);
notification.setLatestEventInfo(this, "title", "content", contentIntent);
notificationManager.notify(NOTIFICATION_ID, notification);
}
2、在需要产生Notification 的地方调用以上方法。
3、取消Notification 的方法:
publicvoid CanllNotification (){
notificationManager.cancel(NOTIFICATION_ID);
}
页:
[1]