说明:
根据项目选择的基础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. 如何在WinForm中发送HTTP请求

    如何在WinForm中请求发送HTTP 手工发送HTTP请求主要是调用 System.Net的HttpWebResponse方法 手工发送HTTP的GET请 求: string strURL = &q ...

  2. 背水一战 Windows 10 (8) - 控件 UI: StateTrigger

    [源码下载] 背水一战 Windows 10 (8) - 控件 UI: StateTrigger 作者:webabcd 介绍背水一战 Windows 10 之 控件 UI VisualState 之 ...

  3. [转] 基于PHP Stream Wrapper开发有趣应用场景

    PHP Stream Wrapper 原文:http://blog.sina.com.cn/s/blog_502c8cc40100k40e.html ,主要是基于SAE环境讲述相应的应用场景,本文经过 ...

  4. 由一个异常开始思考springmvc参数解析

    首先记录一下异常,以及异常出现的原因和解决方案 异常主要信息: -- ::, ERROR [.jsp] - Name for argument type [java.lang.String] not ...

  5. Oracle 数据库基础学习 (二) 学习小例子:创建一个表,记录商品买卖的情况

      运行环境:Oracle database 11g + PL/SQL Developer ex: --创建一个表 create table plspl_test_product( --加入not n ...

  6. linux下使用forever进行管理

    何为forever:forever可以看做是一个nodejs的守护进程,能够启动,停止,重启我们的app应用.官方的说明是说:A simple CLI tool for ensuring that a ...

  7. Linux修改SSH端口,并禁止Root远程登陆

    1.更改ssh远程登录端口: #vi /etc/ssh/ssh_config将port改为你想要的端口,例如8888.默认是#port 22,把#号删掉改为 port 8888即可. 还要更改以下文件 ...

  8. js 字符串 replace replaceAll

    var str = "男的女的老的少的"; alert(str.replace('的','')); 可以看到替换后的str的值为"男女的老的少的",replac ...

  9. 常用的css命名规则:

    关于团队合作的css命名规范 常用的css命名规则: 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制 ...

  10. CSS3 学习笔记

    border-radius 圆角是做网页永远绕不过的话题,以前基本是通过背景图片做的,有了 CSS3 以后通过属性就 能够搞定,我们可以通过 border-radius 设置元素的圆角半径. bord ...