左边的大图为 largeIcon
右边的Android小机器人为smallIcon
public void notify(View view) throws Exception
{
//Notification add Light/Sound/Vibrate
int defaultType = 0;
defaultType |= Notification.DEFAULT_LIGHTS;
defaultType |= Notification.DEFAULT_SOUND;
defaultType |= Notification.DEFAULT_VIBRATE;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setDefaults(defaultType);
builder.setContentInfo("ContentInfo");
builder.setContentText("ContentText");
builder.setContentTitle("ContentTitle");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeStream(getAssets().open("a.png")));
builder.setTicker("Ticker");
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(1, notification);
}
本文介绍如何使用Android系统的Notification API创建带有灯光、声音及震动效果的通知。通过NotificationCompat.Builder构造器设置内容信息、图标,并最终通过NotificationManager显示通知。
1066

被折叠的 条评论
为什么被折叠?



