//api 11 版本以前:
protected void showNotification() { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //Notification notification = new Notification(this,R.drawable.ic_launcher); Notification notification = new Notification(R.drawable.ic_launcher,"",System.currentTimeMillis() ); PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(MainActivity.this, "您的BMI值太高", "通知監督人", contentIndent); //加i是爲了顯示多條Notification notificationManager.notify(i,notification); i++; }
// api 11 版本以後:
protected void showNotification2() { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Builder builder = new Notification.Builder(MainActivity.this); PendingIntent contentIndent = PendingIntent.getActivity(MainActivity.this, 0, new Intent(MainActivity.this,MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIndent).setSmallIcon(R.drawable.ic_launcher)//設置狀態欄裏面的圖標(小圖標) .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.i5))//下拉下拉列表裏面的圖標(大圖標) .setTicker("this is bitch!") //設置狀態欄的顯示的信息 .setWhen(System.currentTimeMillis())//設置時間發生時間 .setAutoCancel(true)//設置能夠清除 .setContentTitle("This is ContentTitle")//設置下拉列表裏的標題 .setContentText("this is ContentText");//設置上下文內容 Notification notification = builder.getNotification(); //加i是爲了顯示多條Notification notificationManager.notify(i,notification); i++; }