Notification的用法

Notification的用法:查看文档

 

 实现步骤:

        // 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,并传递值blacknumber

posted @ 2013-06-25 01:01  tagie  阅读(426)  评论(0编辑  收藏  举报