// 获取NotificationManager NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //此方法已被废弃,现使用Builder模式 // Notification notification = new Notification(R.drawable.icon3,"提醒",System.currentTimeMillis()); // Builder模式 Notification.Builder builder = new Builder(this); // 点击之后的响应 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,MainActivity.class) , 0); builder.setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()) .setContentTitle("通知") .setContentText(data) //@value String data = "data" .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setContentIntent(pendingIntent); manager.notify(3, builder.build()); // builder.getNotification();方法也被废弃了,注意使用build()方法
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-10 01:56:05