说明:
根据项目选择的基础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的更多相关文章

  1. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  2. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  3. 3、android notification 详细用法

    在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以确认保存成功. * 如果应用程序在后台 ...

  4. Android NOtification 使用(震动 闪屏 铃声)

    一. Notification 简介 在 android 系统中,在应用程序可能会遇到几种情况需要通知用户,有的需要用户回应,有的则不需要,例如: * 当保存文件等事件完成,应该会出现一个小的消息,以 ...

  5. Android Notification通知详细解释

    Android Notification通知具体解释  Notification: (一).简单介绍:         显示在手机状态栏的通知. Notification所代表的是一种具有全局效果的通 ...

  6. android notification,notificationmanager详解

    我们知道在使用Android的通知的时候一定会用到NotificationManager . Notification这两个类,这两个类的作用分别是: NotificationManager :  是 ...

  7. android:Notification实现状态栏的通知

    在使用手机时,当有未接来电或者新短消息时,手机会给出响应的提示信息,这些提示信息一般会显示到手机屏幕的状态栏上. Android也提供了用于处理这些信息的类,它们是Notification和Notif ...

  8. Android Notification通知简介

    Android Notification通知简介 根据activity的生命周期,在activity不显示时,会执行onStop函数(比如按下home键),所以你在onStop函数(按退出键除外)里面 ...

  9. Android Notification 消息通知 相关资料.md

    目录 Android Notification 消息通知 相关资料 Android 5.0 Lollipop (API 21)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...

随机推荐

  1. PHP表单数据写入MySQL代码

    <h1>插入操作</h1> <?php if(!isset($_POST['submit'])){ //如果没有表单提交,显示一个表单 ?> <form ac ...

  2. Monotype推出基于HTML5的Web字体平台

    著名字体公司Monotype近日宣布推出基于HTML5的Web字体平台,设计者可以访问近10万字体的目录. Monotype推出基于HTML5的Web字体平台 Monotype推出基于HTML5的We ...

  3. 使用C#向Sql Sever中存取网络图片和本地图片(二进制流的形式)

    先是做普通的,存储我们本地的图片,将它转化为二进制流存储到数据库对应的表中. 代码如下: string path = "../../A.jpg"; FileStream fs = ...

  4. Oracle数据库,非空约束、主键约束、外键约束、唯一约束

    非空约束:设置列时,可为空默认可为空,去掉对号之后设置数据不可为空: 唯一约束:在键中设置,唯一约束名称.类型Unique.列名:设置应用完成之后,此列数据具有唯一性:即数据不可重复(类型:Uniqu ...

  5. 第 14 章 CSS 颜色与度量单位

    学习要点: 1.颜色表方案 2.度量单位 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS 颜色和度量单位等问题,包括颜色的选取方式.相对长度和绝对长度等. 一.颜色表方案 颜色的表现形式主要有 ...

  6. PMP47个过程的ITO

  7. 2016 大连网赛---Different GCD Subarray Query(GCD离散+树状数组)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5869 Problem Description This is a simple probl ...

  8. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

  9. POJ 3276 Face The Right Way 反转

    大致题意:有n头牛,有些牛朝正面,有些牛朝背面.现在你能一次性反转k头牛(区间[i,i+k-1]),求使所有的牛都朝前的最小的反转次数,以及此时最小的k值. 首先,区间反转的顺序对结果没有影响,并且, ...

  10. GJM : 基于Actor模式的c#网络游戏服务器的实现和Unity游戏客户端的连接 [转载]

    感谢您的阅读.喜欢的.有用的就请大哥大嫂们高抬贵手"推荐一下"吧!你的精神支持是博主强大的写作动力以及转载收藏动力.欢迎转载! 版权声明:本文原创发表于 [请点击连接前往] ,未经 ...