通知——Notification

来源:互联网 发布:php curl 设置编码 编辑:程序博客网 时间:2024/05/17 04:35

一、界面提醒概述

界面交互,在用户体验设计中是很重要的一环。在Android界面提醒有如下三种方式:

  • Toast
  • Dialog
  • notification -通知

二、Notification概述

通知是运行在一个叫做 com.android.systemui的进程里面。通知要使用过程中分高版本(16版本以上)、低版本(16版本以下),两个版本有不同实现。其中高版本兼容低版本。

  • 高版本
//1.先拿到通知管理器NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);//下面要求是11版本以上的Notification noti = new Notification.Builder(this).setContentTitle("标题——呵呵").setContentText("内容—哈哈哈").setSmallIcon(R.drawable.ic_launcher).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))//这句要求API16以上.build();manager.notify(1, noti);
  • 低版本
//1.先拿到通知管理器NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);Intent intent = new Intent();intent.setAction(Intent.ACTION_CALL);intent.setData(Uri.parse("tel://10086"));//1.拿到PendingIntentPendingIntent contentIntent=PendingIntent.getActivity(this, 1, intent, 0);Notification noti2 = new Notification(R.drawable.ic_launcher, "你有一条未读短信", System.currentTimeMillis());noti2.setLatestEventInfo(this, "标题——哈哈", "内容—呵呵", contentIntent);manager.notify(1, noti2);
0 0