Notification的用法:查看文檔this
實現步驟:spa
// 1.獲取NotificationManager String ns = Context.NOTIFICATION_SERVICE; NotificationManager manager = (NotificationManager) getSystemService(ns); // 2.初始化Notification int icon = R.drawable.notification; CharSequence tickerText = "攔截到一個一聲響鈴號碼"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); // 點擊後提示對話框自動消失 // 3.定義Notification的具體內容和點擊事件 Context context = getApplicationContext(); CharSequence contentTitle = "發現一聲響鈴"; CharSequence contentText = "號碼爲;" + incomingNumber; notification.flags = Notification.FLAG_AUTO_CANCEL; Intent notificationIntent = new Intent(this, CallSmsSafeActivity.class); notificationIntent.putExtra("blacknumber", incomingNumber); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); // 4.利用NotifyManager通知顯示消息提示 manager.notify(0, notification);
點擊Notification的界面能夠進入CallSmsSafeActivity,並傳遞值blacknumbercode