zoukankan      html  css  js  c++  java
  • 通知的基本用法

    通知的基本用法
    想要让手机弹出一条通知,只需要使用如下代码:
    val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    val notification = NotificationCompat.Builder(context, channelId)
            .setContentTitle("This is content title")
            .setContentText("This is content text")
            .setSmallIcon(R.drawable.small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon))
            .build()
    manager.notify(1, notification)

    想要指定通知的点击事件,只需要使用如下代码:
    
    val intent = Intent(this, NotificationActivity::class.java)
    val pi = PendingIntent.getActivity(this, 0, intent, 0)
    val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    val notification = NotificationCompat.Builder(context, channelId)
            .setContentTitle("This is content title")
            .setContentText("This is content text")
            .setSmallIcon(R.drawable.small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.large_icon))
            .setContentIntent(pi)
            .build()
    manager.notify(1, notification)
  • 相关阅读:
    django ajax使用
    vim--分屏快捷键
    django csrf
    django mysql使用
    官方文档地址
    图解http 学习
    Terms
    Data Center Group
    Misc
    FTDI CDM Drivers 2.06.00
  • 原文地址:https://www.cnblogs.com/yongyuandishen/p/14905116.html
Copyright © 2011-2022 走看看