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     }
  • 相关阅读:
    凡是可能出错的事必定会出错
    php session 前后台同域名下
    mysql常用; group by 高级
    Thread 学习记录 <1> -- volatile和synchronized
    VBA学习
    EXPLAINING WHAT ACTION AND FUNC ARE
    Unslider.js Tiny Sample
    jQuery操作DOM元素
    在.net中使用GAC
    Sql Server 分区演练 【转】
  • 原文地址:https://www.cnblogs.com/hais/p/4691587.html
Copyright © 2011-2022 走看看