您的位置:首页 > 其它

关于创建notification

2016-04-25 14:07 309 查看
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this,NatificationActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_CANCEL_CURRENT);
<pre name="code" class="java">              /*** 低于API Level 11版本,也就是Android 2.3.3以下的系统中,* setLatestEventInfo()函数是唯一的实现方法。*///                Notification notification = new Notification(R.mipmap.ic_launcher, "This is ticker text", System.currentTimeMillis());//                Intent  intent = new Intent(this,MainActivity.class);//                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);//                notification.setLatestEventInfo(this, title, message, pendingIntent);//                manager.notify(id, notification);//                notification.setLatestEventInfo(this, "This is content title","This is content text", null);
<pre name="code" class="java">                /*** 高于API Level 11,低于API Level 16 (Android 4.1.2)版本的系统中,* 可使用Notification.Builder来构造函数。* 但要使用getNotification()来使notification实现。*/Notification.Builder builder = new Notification.Builder(this).setAutoCancel(true).setTicker("This is ticker text").setContentTitle("This is content title").setContentText("This is content text").setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setWhen(System.currentTimeMillis())//                        .setVibrate(new long[]{0,500}).setDefaults(Notification.DEFAULT_ALL).setOngoing(false);Notification notification = builder.getNotification();//                notification.ledARGB = Color.RED;//                notification.ledOnMS = 500;//                notification.ledOffMS = 500;//                notification.flags = Notification.FLAG_SHOW_LIGHTS;
                /***  高于API Level 16的版本,*  就可以用Builder和build()函数来配套的方便使用notification了。*///                Notification notification = new Notification.Builder(this)//                        .setAutoCancel(true)//                        .setContentTitle("This is content title")//                        .setContentText("This is content text")////                      .setContentIntent(pendingIntent)//                        .setSmallIcon(R.mipmap.ic_launcher)//                        .setWhen(System.currentTimeMillis())//                        .setOngoing(false)//                        .build();
manager.notify(1, notification);

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: