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

  • 相关阅读:
    Android Studio 中关于NDK编译及jni header生成的问题
    为YAESU FT-817ND 增加频谱功能
    Nagios 安装配置
    ubuntu 13.10 Ralink RT3290 无线与蓝牙4.0的驱动安装
    golang全文搜索--使用sphinx
    GNU Radio 之 rtl-sdr
    OsmocomBB && Motorora C118
    OsmocomBB 编译安装
    Go 若干技巧
    Docker内核知识
  • 原文地址:https://www.cnblogs.com/tagie/p/3153999.html
Copyright © 2011-2022 走看看