创建android Notification
说明:
根据项目选择的基础sdk,选择不同的创建Notification的方法
1 在android sdk 3.0 之前直接通过 new Notification的方法直接创建通知对象
2 在android sdk 3.0 是通过Notification.Builer的方法间接配置Notification的属性和创建Notification的功能
3 在android sdk4.0以上 是通过android-support-v4.jar 包中的NotificationCompat.Builder类,进行配置创建Notification对象
下面是一个实例,用NotificationCompat.Builder的方式创建Notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!"); //Notification.Builder builder=new Notification.Builder(this); mBuilder.setAutoCancel(true);
mBuilder.setLights(Color.BLUE, 500, 500);
long[] pattern = {500,500,500,500,500,500};
mBuilder.setVibrate(pattern); Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.messagevoice);
mBuilder.setSound(sound);
//mBuilder.setSound(sound);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MessageShowActivity.class); // The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
//stackBuilder.addParentStack(MessageShowActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(this, 0, new Intent(this,MessageShowActivity.class), 0); mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(12, mBuilder.build());
创建android Notification的更多相关文章
- Android Notification 详解(一)——基本操作
Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...
- Android Notification 详解——基本操作
Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...
- 3、android notification 详细用法
在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以确认保存成功. * 如果应用程序在后台 ...
- Android NOtification 使用(震动 闪屏 铃声)
一. Notification 简介 在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以 ...
- Android Notification通知详细解释
Android Notification通知具体解释 Notification: (一).简单介绍: 显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...
- android notification,notificationmanager详解
我们知道在使用Android的通知的时候一定会用到NotificationManager . Notification这两个类,这两个类的作用分别是: NotificationManager : 是 ...
- android:Notification实现状态栏的通知
在使用手机时,当有未接来电或者新短消息时,手机会给出响应的提示信息,这些提示信息一般会显示到手机屏幕的状态栏上. Android也提供了用于处理这些信息的类,它们是Notification和Notif ...
- Android Notification通知简介
Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...
- Android Notification 消息通知 相关资料.md
目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...
随机推荐
- css3飞机起飞进度条
效果:http://hovertree.com/texiao/css3/27/ 源码下载:http://hovertree.com/h/bjaf/pgwql1x2.htm 本效果使用Font Awes ...
- 迷信AgainAndAgain
又重新在VBox中安装Debian其它镜像两次,依然在安装桌面软件包时挂掉...
- EasyUI-加载完Html内容样式渲染完成后显示
等待页面的css样式加载完毕,Html内容加载完毕,样式生成后再进行展示,避免一开始加载内容后,逐渐渲染样式造成的不良视觉效果,增强用户体验. 新增base-loading.js文件,代码如下 //获 ...
- [moka同学笔记]MySql语句整理
更改单个表中的字段属性 content 以前为text类型的,现在改为longtext ALTER TABLE `notice` CHANGE `content` `content` LONGTEXT ...
- Java final方法
之所以要使用final方法,可能是出于对两方面理由的考虑.第一个是为方法"上锁",防止任何继承类改变它的本来含义.设计程序时,若希望一个方法的行为在继承期间保持不变,而且不可被覆盖 ...
- 使用 WSO2 API Manager 管理 Rest API
WSO2 API Manager 简介 随着软件工程的增多,越来越多的软件提供各种不同格式.不同定义的 Rest API 作为资源共享,而由于这些 API 资源的异构性,很难对其进行复用.WSO2 A ...
- linux常用命令之文件权限
CHGRP chgrp – change group ownership,改变组别的所有权 用法 chgrp 组别名 文件\目录名 选项 -R (recursive)递归改变,将目录下所有的文件和目 ...
- Redis 3.2.1集群搭建
一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):slave->master ...
- 如何订阅Form的自定义事件
Window Form类有很多的属性/方法和事件,其中事件属于一种发布订阅模式 .订阅发布模式定义了一种一对多的依赖关系,让多个订阅者对象同时监听某一个主体对象.这个主体对象在自身状态变化时,会通知所 ...
- BeeFree - 在线轻松创建电子邮件消息
Beefree 可以很容易地创建一个电子邮件消息,可以被用来发送企业简讯,宣布一个新产品,促进销售等.可以免费使用,您甚至不需要创建任何类型的帐户.您可以使用 Beefree 创建创新的,易于使用的电 ...