zoukankan      html  css  js  c++  java
  • Android 通知Notification

    Android 通知栏Notification的简但使用,效果如上图,废话不说,代码:

     1 private void notification() {
     2         Notification notification;
     3         int notification_id = 11;
     4 
     5         //通过系统服务来获取对象
     6         NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
     7         //创建一个通知对象
     8         Notification.Builder nbuider = new Notification.Builder(MainActivity.this);
     9         //设置Notification的效果为默认效果
    10         nbuider.setDefaults(Notification.DEFAULT_LIGHTS);
    11         //设置Notification 第一次出现在状态拦下的文本
    12         nbuider.setTicker("通知你去出差!");
    13         //标题
    14         nbuider.setContentTitle("通知");
    15         //小标题
    16         nbuider.setContentTitle("就是了");
    17         //小标题
    18         nbuider.setContentText("好啊");
    19         //延迟0ms,然后振动500ms,延迟300ms,接着振动350ms。
    20         nbuider.setVibrate(new long[]{0,500,300,350});
    21         nbuider.setSmallIcon(R.drawable.e);//不设置图标出不来,不知什么情况
    22 
    23         //创建Intent对像,作为pendingIntent 参数
    24         Intent intent = new Intent(MainActivity.this,AnimationActivity.class);
    25         //Activity与pendingIntent关联的对象
    26         PendingIntent pi = PendingIntent.getActivity(MainActivity.this,0,intent,0);
    27 
    28 
    29         //打开触发
    30         nbuider.setContentIntent(pi);
    31 
    32         //创建通知
    33         notification =nbuider.build();//API 16以上才能使用
    34         notification.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知后原来文本图标消失
    35         //发送通知
    36         notificationManager.notify(notification_id,notification);
    37     }
  • 相关阅读:
    感觉每天打开自己的博客园, 想编程的心情就多了起来~~~
    算法图解相关代码整理
    github cli
    What's WebFlux ? And how to use it ? 一股有咖喱味的WebFlux简介
    style
    gradle 1
    gradle打包可运行jar
    外面下着雨
    天晴朗 看花儿多多开放
    Full Stack Reactive with React and Spring WebFlux
  • 原文地址:https://www.cnblogs.com/hais/p/4691587.html
Copyright © 2011-2022 走看看