[Android] 在5.0中的 Notification

关于 Notification 的用法可以在我的 Github 上找到: https://github.com/celesteshire/NotificationDemo

普通.gif
折叠.gif
悬挂.gif

下面来看看关于部分源码的解释

在 Notification 类的内部,还有一个 Builder 内部类,通过 Builder 类,能方便的构造 Notification

public Builder setWhen(long when) {  
  mWhen = when;  
  return this;  
}  

设置一个时间,在显示通知的时候会根据这个时间在通知栏进行排序。

public Builder setSmallIcon(int icon) {  
  mSmallIcon = icon;  
  return this;  
}  

设置小图标的方法

 public Builder setContentTitle(CharSequence title) {  
   mContentTitle = title;  
   return this;  
}  

设置标题栏文本

public Builder setContentText(CharSequence text) {  
  mContentText = text;  
  return this;  
}  

设置正文文本

public Builder setContentIntent(PendingIntent intent) {  
  mContentIntent = intent;  
  return this;  
}  

提供一个PendingIntent,在点击的时候会得到调用

public Builder setSound(Uri sound) {  
  mSound = sound;  
  mAudioStreamType = STREAM_DEFAULT;  
} 

设置提示音,传入一个音频的 Uri

public Builder setVibrate(long[] pattern) {  
  mVibrate = pattern;  
  return this;  
} 

设置震动

public Builder setAutoCancel(boolean autoCancel) {  
  setFlag(FLAG_AUTO_CANCEL, autoCancel);  
  return this;  
}  

设置是否自动取消

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容