widget(10、Notification)

Notification即通知栏,在android中常用如下几种功能:

1、客户端功能提示,如版本升级;

2、收到短信、新闻等提示;

3、显示当前情况,如下载进度等;

Notification基本应用如下:

        Intent notifyIntent = new Intent(this, MainActivity.class);
        PendingIntent notify_Intent = PendingIntent.getActivity(this, 0,
                notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        
        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        
        mNotification = new NotificationCompat.Builder(getApplicationContext())
        .setSmallIcon(R.drawable.ic_launcher)
        .setTicker("showNormal").setContentInfo("contentInfo")
        .setContentTitle("title").setContentText("content")
        .setNumber(1).setContentIntent(notify_Intent)
        .setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL)
        .build();
        
        mNotificationManager.notify(0, mNotification);
  • 其中PendingIntent为延迟Intent是一个Intent的封装,用以处理点击nofication后的跳转,如本例中则是回到原activity;
  • setSmallIcon用以设置notification的小图标;
  • setTicker是显示notification发生时,在手机顶端出现的提示动画效果;
  • setContentText、setContentTitle显示notification提示的标题和内容;
  • setDefault设置提示用的方式,如默认铃声等;notification还可以设置震动、灯光等;
  • NotificationMananger是一个通知的管理类,负责notification的发送、清除等;

 

posted @ 2013-01-24 14:16  Fredric_2013  阅读(370)  评论(0编辑  收藏  举报