Android用户界面之notifaction(状态栏通知)
来源:互联网 发布:下载dreamweaver软件 编辑:程序博客网 时间:2024/06/05 16:49
对于通知,应先明白:通知概要 通知标题 通知内容 通知图标 通知时间
首先,看界面。状态栏上的是:图标和概要。
将状态栏往下拉,会出来标题、内容和时间。
通知除了状态栏的图标外,还可以 开打设备上的LED灯,发送声音、震动来提醒用户
通知可以告诉用户在后台发生了某事,所以经常在广播接受者和服务中使用;
例子开始的界面如下:点击发送后,会发送通知。
主要用到的方法有:
1、得到通知管理者:通过getSystemService(String)
.来得到NotificationManager,在该类中调用cancel(int)来清除通知。
2、指定通知的最新信息:notification.setLatestEventInfo(this, title, content, pendingIntent);
3、 PendingIntent类解析:
带有特定标记(flag)的的intent,由静态方法getActivity(Context, int, Intent, int flag)
,getBroadcast(Context, int, Intent, int flag)
,getService(Context, int, Intent, int flag)
来创建。
主要标记有:
FLAG_UPDATE_CURRENT :如果已经存在PendingIntent,还产生该PendingIntent,还带有新的extra
FLAG_ONE_SHOT :这个PendingIntent只能被用一次。
FLAG_CANCEL_CURRENT:如果存在的PendingIntent还未消失,还取消将将要产生的该PendingIntent
主要代码:
- String tickerText = shortText.getText().toString();
- String title = titleText.getText().toString();
- String content = contentText.getText().toString();
- //1、得到NotificationManager
- NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
- //2、实例化一个通知,指定了图标、概要、时间
- Notification notification = new Notification(android.R.drawable.stat_notify_chat, tickerText, System.currentTimeMillis());
- //3、指定通知的标题、内容和intent
- Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:104040444"));
- PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
- notification.setLatestEventInfo(this, title, content, pendingIntent);
- //指定标志和声音
- notification.flags = Notification.FLAG_AUTO_CANCEL;
- notification.defaults = Notification.DEFAULT_SOUND;
- //可以指定为震动,也可以用 .sound来自己指定声音
- //notification.defaults = Notification.DEFAULT_VIBRATE;
- //可以指定为闪光灯
- //notification.defaults = Notification.DEFAULT_LIGHTS;
- //4、发送通知给通知管理者
- manager.notify(1, notification);
- Android用户界面之notifaction(状态栏通知)
- Android用户界面之notifaction(状态栏通知)
- Android用户界面之notifaction(状态栏通知)
- Android 用户界面---状态栏通知(一)
- Android 用户界面---状态栏通知(二)
- Android 用户界面---状态栏通知(三)
- Android 用户界面---状态栏通知(一)
- Android 用户界面---状态栏通知(二)
- Android 用户界面---状态栏通知(三)
- android之notifaction
- Android通知之状态栏通知
- android开发之向状态栏发送通知
- Android入门笔记之状态栏通知
- Android之状态栏通知Notification、NotificationManager详解
- Android 用户界面---通知(Notifications)概要
- Android 用户界面---广播通知(Toast Notifications)
- Android 用户界面---通知(Notifications)概要
- Notifaction安卓通知栏
- CCI习题1-1:String Contain Unique Char
- linux下安装apache
- 互斥锁Mutex与信号量Semaphore的区别
- 评教系统需求了解
- 枚举串口四法
- Android用户界面之notifaction(状态栏通知)
- 软件开发流程来自百度
- GDI+的使用
- 数组--结构体数组
- ARM9 S3C2440 FCLK,HCLK,PCLK时钟的关系
- 写一个交换函数,在主程序中调用该函数,来实现实参值的交换。
- MVC框架是什么
- Linux下使用Virtualenv搭建Django开发环境
- C# 给groupbox加滚动条