Android Notifications
来源:互联网 发布:windows git 版本升级 编辑:程序博客网 时间:2024/05/20 20:05
Android Notifications
一条通知消息是显示于你用于正常UI之外的地方。你可以通过点击它来查看通知详情。另外,NotificationCompat.Builder是用于低版本构建的方式,Android 3.0以上使用Notification.Builder来构建。通知显示有两种视图样式,1种是普通视图,1种是大视图(Android4.1以上才行)。
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(this);
builder.setTicker("");
builder.setSmallIcon(R.drawable.xxx);
builder.setContentTitle("");
builder.setContentText("");
Intent intent = new Intent(Activity.this, Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(Activity.this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
builder.setContentIntent(pendingIntent);
manager.notify(id, builder.build());
如果需要添加进度条需要进行如下操作:
new Thread(new Runnable{
builder.setProgress(max, cur, fasle);
manager.notify(id, builder.build());
}).start();
builder.setProgress(0, 0, false);//取消进度条
manager.notify(id, builder.build());
自定义通知:
Notification.Builder builder = new Notification.Builder(Activity.this);
RemoteViews remoteViews= new RemoteViews(getPackageName(), R.layout.xxx);
builder.setTicker("");
builder.setContentTitle("");
builder.setContentText("");
builder.setSmallIcon(R.drawable.xxx);
remoteViews.setTextViewText(R.id.xxx, "");
remoteViews.setImageViewResource(R.id.xxx, R,drawable.xxx);
Intent intent = new Intent(Activity.this, Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(Activity.this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
builder.setContentIntent(pendingIntent);
builder.setContent(remoteViews);
manager.notify(id, builder.build());
0 0
- Android Notifications
- Android: notifications
- Android Notifications
- Android Notifications
- android - Notifications
- Android Notifications
- Android Notifications通知
- Android Notifications通知
- Android Notifications通知
- Android API Guides---Notifications
- Notifications in Android N
- Android 笔记 通知/notifications
- Notifications
- notifications
- Notifications
- Notifications
- Notifications
- Notifications
- 【自研IM系统Talk00】 --- 接口说明
- 关于hashmap使用迭代器的问题
- Linux TCP/IP网络小课堂:net-tools与iproute2大比较
- Spring中@Transactional事务回滚(含实例详细讲解,附源码)
- Android如何关闭硬件加速
- Android Notifications
- linux服务器下mysql的中文乱码问题(解决)
- 数据库查询语句总结
- typedef + 指针 用法说明
- SPOOLing技术的再思考
- Linux一些常用命令
- vagrant配置多机多节点
- Sqoop详细介绍包括:sqoop命令,原理,流程
- Android解决NDK not configured问题