本文地址:http://blog.csdn.net/u011181236/article/details/51455284
注意:最好把小图标按不同分辨率放入多个到项目的drawable中
NotificationManagerCompat managerCompat ;
private Notification initNotfication(){
NotificationCompat.Builder builder = new NotificationCompat.Builder(HomeActivity.this);
//设置小图标
builder.setSmallIcon(R.drawable.icon);
//设置大图标
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher));
builder.setTicker("Ticker");
//设置标题
builder.setContentTitle("ContentTitle");
//设置标题下面的内容
builder.setContentText("ContentText");
//设置右侧时间下面的内容
builder.setContentInfo("ContentInfo");
//设置时间
builder.setWhen(System.currentTimeMillis());
return builder.build();
}
private void shwoNotifi(){
managerCompat = NotificationManagerCompat.from(HomeActivity.this);
if (managerCompat !=null){
managerCompat.notify(0,initNotfication());
}
}