美文网首页
Notification 学习

Notification 学习

作者: Crane_FeiE | 来源:发表于2018-09-17 07:23 被阅读0次

第一行代码中的代码是基于android 7.0进行编写,API的调用已经落后较多

Notification 常用写法:

    private void showNotification() {
        Intent intent = FragmentTestActivity.formatIntent(this);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
        NotificationManager notiManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification.Builder(this)
                .setContentTitle("title")
                .setContentText("test")
                .setWhen(System.currentTimeMillis())        //show time on notification
                .setSmallIcon(R.mipmap.ic_launcher_round)   //icon in the status bar
                .setAutoCancel(true)                        //cancel self when click notification
                .setContentIntent(pi)                       //set the intent handled when click notification
                .build();

        if(notiManager != null){
            notiManager.notify(1, notification);
        }
    }

手动关闭notification:

        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        if(nm != null){
            //1 is the id, which should be the same int value when `notify(int id, Notification notification) called` 
            nm.cancel(1);
        }

NotificationChannel: 8.0 新增特性

下午学习

相关文章

  • Notification 学习

    第一行代码中的代码是基于android 7.0进行编写,API的调用已经落后较多 Notification 常用写...

  • Android Notification学习

    文/大大大大峰哥 概述 在我们Android开发过程Notification是一个使用率较高的组件,我们有理由仔细...

  • 笔记49 | Android通讯之Notification[转]

    地址 目录 Notification 概述 Notification 的基本操作 创建 Notification ...

  • 通知

    Android中Notification 提示对话框,notification 概述 notification,俗...

  • Notification框架简介

    目录 Notification介绍 Notification框架原理 Notification框架服务端启动过程 ...

  • Androd Notification

    The Guide Notification Notification Builder NotificationM...

  • notification

    notification文档 桌面通知 notification 示例

  • Notification详解

    Notification详解 Notification的使用步骤 自定义Notification样式 自定义Not...

  • Notification 总结

    Notification Notification 能干什么,那些设计是和Notification相关的;这里直接...

  • Android Notification的使用

    Notification的作用 能够在通知栏展示一些信息 Notification介绍 notification-...

网友评论

      本文标题:Notification 学习

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