建立Notification

在Notification类中setLatestEventInfo()方法显示过期,所以使用另外一种方式建立一个简单的通知(PS:在Activity中)java

NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

                                  Notification.Builder builder=new Builder(context);

                                  builder.setContentTitle("xxxx");//设置标题

                                  builder.setContentText("xxxx");//设置内容

                                  builder.setSmallIcon(com.example.pushdemo2.R.drawable.ic_launcher);//定义左边的小图标

                                  builder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE);//设置提示声音

                                  Intent intent=new Intent(context, Main.class);

                                  PendingIntent penIntent=PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, null);

                                  builder.setContentIntent(penIntent);//设置跳转界面

                                  builder.setAutoCancel(true);//设置点击通知栏后自动消失

                                  Notification notification=builder.build();

                                  notificationManager.notify(1, notification);
相关文章
相关标签/搜索