zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    「题解」洛谷 P1731 [NOI1999]生日蛋糕
    「题解」洛谷 P1063 能量项链
    Log4j2笔记
    基数排序
    会计知识
    归并排序
    CF668 题解
    拉格朗日反演
    [国家集训队]数颜色 / 维护队列 「带修莫队」
    简单的填数「贪心」
  • 原文地址:https://www.cnblogs.com/tagie/p/3153999.html
Copyright © 2011-2022 走看看