美文网首页
android 通知

android 通知

作者: EvanPoison | 来源:发表于2017-05-25 11:29 被阅读12次
  1. notification需要一个NotificationManager来管理,如何获取呢?
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  2. 然后使用builder构造器来构造一个Notification对象,为了兼容性,最好使用v4包中的NotificationCompat
 Notification notification =  new NotificationCompat.Builder(this)
                .setContentTitle("hello")
                .setContentText("test")
                .setWhen(System.currentTimeMillis())
                .setSmallIcon()
                .setLargeIcon()
                .build();
  1. 最后调用NotificationManager的notify()方法
  2. 以上步骤创建的通知是无法点击的,需要设置PendingIntent
    PendingIntent有几个静态方法用来获取对象
PendingIntent.getActivities()
PendingIntent.getBroadcast()
PendingIntent.getService()

NotificationCompat.Builder里有个方法:setContentIntent()来设置这个延迟的意图

5.通知的关闭

  • 方式一:NotificationCompat.Builder中再加上setAutoCancel(),当通知被点击后,消失
  • 方式二:显式的调用NotificationManager的cancel()方法
  1. 更高级的通知,待续。。。

相关文章

  • Android直接回复通知

    Android直接回复通知 通知直接回复 Android N/7.0 前言 通知(Notification)可为是...

  • 《Android第一行代码》first reading 十

    Android多媒体运用 一 通知 使用Android通知功能步骤: 通过Context的getSystemSer...

  • Android的通知

    通知是什么? 通知存在的意义是什么? Android O(Android SDK Api Level 26,And...

  • android通知

    1.这里写了一个常用的通知的代码

  • Android通知

    通知在实际开发中还是比较常见的,例如新闻,音乐播放器,等。 1,基本通知 2,基础扩展通知自定义布局 xml >>...

  • android 通知

    notification需要一个NotificationManager来管理,如何获取呢?Notification...

  • Android通知

    在这里写一个Android的通知,相应的图标以及位置大概也有介绍,需要的时候可以试试;

  • Android 通知

    Android 8.0中各种通知写法汇总https://www.jianshu.com/p/6aec3656e27...

  • Android:通知

    如果你将项目中的targetSdkVersion指定到了26或者更高(targetSdkVersion可以在app...

  • Android 8.0 Notification

    Android 8.0 通知适配: Android Api 26 Notification Builder 构建...

网友评论

      本文标题:android 通知

      本文链接:https://www.haomeiwen.com/subject/ulgaxxtx.html