//获得通知管理器 NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE) //创建通知对象,参数依次为通知图标、ticker(通知栏上一闪而过的信息)、通知创建时间 Notification notification = new Notification(R.drawable. ic_launcher, "This is ticker text", System.currentTimeMillis()); //设置通知布局,参数依次为Context,通知标题、通知正文、PindingIntent对象(点击通知之后的事件处理) notification.setLatestEventInfo(this, "This is content title", "This is content text", null); //显示通知,参数依次为唯一的id、通知对象 manager.notify(1, notification);
//1、获得通知管理器
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//创建Builder,设置属性
Notification.Builder builder = new Notification.Builder(this)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("describe")
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setOngoing(true);
//获得Notification对象
Notification notification = builder.getNotification();
//显示通知
manager.notify(1, notification);
//1、获得通知管理器
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//创建Builder,设置属性
Notification notification = new Notification.Builder(this)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("describe")
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.build();
//显示通知
manager.notify(1, notification);
//获得通知管理器
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
//构造Intent对象
Intent intent = new Intent(MainActivity.this, TestActivity.class);
//获得PendingIntent对象
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
//创建Builder,设置属性
Notification notification = new Notification.Builder(this)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("describe")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pendingIntent) //设置PendingIntent
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.build();
//显示通知
manager.notify(1, notification);
//音频Uri
Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones"));
setSound(soundUri);
//手机振动静止设置(静止0秒,振动一秒,静止一秒,振动一秒)
long[] vibrate = {0, 1000, 1000, 1000};
setVibrate(vibrate)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有