Notification可以作为状态栏的通知,实现这个效果需要使用NotificationManager实现控制类,才能实现对这个效果的显示

下面是实现状态栏显示效果的通知:

1. 首先在Layout建立两个Button,一个用于实现显示Notification,一个用于取消Notification

2. 书写Java代码

private void sendNotification(){

Intent intent = new Intent(this,MainActivity.class);

PendingIntent pintent = PendingIntent.getActivity(this, 0, intent, 0);

Builder builder =new Notification.Builder(this);[s1]

builder.setSmallIcon(R.drawable.ic_launcher);//设置图标

builder.setTicker("hello");//手机状态栏的提示;

builder.setWhen(System.currentTimeMillis());//设置时间

builder.setContentTitle("通知栏通知");//设置标题

builder.setContentText("我来自NotificationDemo");//设置通知内容

builder.setContentIntent(pintent);//点击后的意图

// builder.setDefaults(Notification.DEFAULT_SOUND);//设置提示声音

// builder.setDefaults(Notification.DEFAULT_LIGHTS);//设置指示灯

// builder.setDefaults(Notification.DEFAULT_VIBRATE);//设置震动

builder.setDefaults(Notification.DEFAULT_ALL);//设置震动

Notification notification = builder.build();//4.1以上

//builder.getNotification();

manager.notify(notification_ID[s2] , notification);

}

Ps:

-------------------------------------------------------------------------------------

在创建前明确导入的包


[s1]创建Notification的Builder

[s2]需要定义变量,这条语句的意思是用于显示Notification

Android成长日记-Noification实现状态栏通知的更多相关文章

  1. Android应用开发学习之状态栏通知

    作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 状态栏通知涉及到两个类,一是Notification,它代表一个通知:另一个是NotificationManager ...

  2. Android成长日记-Android四大组件之Service组件的学习

    1.什么是Service? Service是Android四大组件中与Activity最相似的组件,它们都代表可执行的程序,Service与Activity的区别在于:Service一直在后台运行,它 ...

  3. Android成长日记-数据存储之SQLite[1]

    [SQLite简介] SQLite是R.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准,并且可以在所有主要的操作系统上运行 ---支持高达2TB大小的数据库: ...

  4. Android成长日记-五大布局

    1. 五布局之线性布局LinearLayout 特点:它包含的子控件将以横向或竖向的方式排列 ps:android:gravity=”center|bottom”(gravity允许多级联用) Tip ...

  5. Android成长日记-数据存储之SharedPreferences

    数据篇-SharedPreferences Android的四种存储方式 1. SharedPreferences 2. SQLite 3. Content Provider 4. File ---- ...

  6. Android成长日记-使用ViewFlipper实现屏幕切换动画效果

    (一) ViewFlipper介绍 Android系统自带的一个多页面管理控件,它可以实现子界面的自动切换 (二) 为ViewFlipper加入View 1. 静态导入:在Layout布局文件中直接导 ...

  7. Android成长日记-使用ToggleButton实现灯的开关

    案例演示 此案例实现思路:通过ToggleButton控件,ImageView控件实现 ---xml代码: <!-- textOn:true textOff:falase[s1] --> ...

  8. Android成长日记-使用PagerAdapter实现页面切换

    Tip:此方式可以实现页面切换 1. 创建view1.xml,view2.xml,view3.xml,main.xml 在main.xml中创建 <android.support.v4.view ...

  9. Android成长日记-使用Intent实现页面跳转

    Intent:可以理解为信使(意图),由Intent来协助完成Android各个组件之间的通讯 Intent实现页面之间的跳转 1->startActivity(intent) 2->st ...

随机推荐

  1. 【点滴积累,厚积薄发】windows schedule task中.exe程序的路径问题等问题总结

    1.在发布ReportMgmt的Job时遇到一个路径问题,代码如下: doc.Load(@"Configuration\Business\business.config");   ...

  2. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  3. React Native开发技术周报2

    (1).资讯 1.React Native 0.22_rc版本发布 添加了热自动重载功能 (2).技术文章 1.用 React Native 设计的第一个 iOS 应用 我们想为用户设计一款移动端的应 ...

  4. MVC5 + EF6 + Bootstrap3 (15) 应用ModelState和Data Annotation做服务器端数据验证

    Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-server-side-validation.html 系列 ...

  5. Oracle 常用操作【01】修改、更新数据

    1. oracle 修改表名.列名.字段类型.添加表列.删除表列  alert table scott.test rename to test1--修改表名 alter table scott.tes ...

  6. Pattern Recognition And Machine Learning读书会前言

    读书会成立属于偶然,一次群里无聊到极点,有人说Pattern Recognition And Machine Learning这本书不错,加之有好友之前推荐过,便发了封群邮件组织这个读书会,采用轮流讲 ...

  7. 如何配置多个ssh key

    上一篇简单学习了下怎样利用git bash上传文件到指定的github项目中,我们来回顾下.首先在本地安装好git,设置好用户名和邮箱(提交时的显示),接着我们生成SSH key把它添加到该项目own ...

  8. 实用工具 : Xaml Power Toys

    最近挺忙, 憋了一肚子的东西没有分享. 今天分享一个 Xamarin.Forms / WPF 的增强工具 , Visual Studio 扩展 : Xaml Power Toy 可以直接在 VS201 ...

  9. 此utf8 非彼utf8 ——谈http协议里的编码问题

    我这里看两个编码: BDPAGETYPE:2BDQID:0xc92b034d0bc985e8BDUSERID:809441751 Cache-Control:private Connection:Ke ...

  10. Scala函数式编程进阶

    package com.dtspark.scala.basics /** * 函数式编程进阶: * 1,函数和变量一样作为Scala语言的一等公民,函数可以直接赋值给变量: * 2, 函数更长用的方式 ...