创建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)无法正常显示通知图标,只能看到一个白色方块或灰色方块的问题 解决方案 参考 ...
随机推荐
- 【SQL】靠谱的TRIM函数,附赠过程一枚
SQL中有LTRIM和RTRIM这两个函数分别用于去除字符串的首.尾空格,缺乏常见的能同时去除首尾的TRIM函数,另外,这俩函数都只对[空格]有效,所以如果首尾是制表符.换行符等等[空白],它们是不处 ...
- 点/边 双连通分量---Tarjan算法
运用Tarjan算法,求解图的点/边双连通分量. 1.点双连通分量[块] 割点可以存在多个块中,每个块包含当前节点u,分量以边的形式输出比较有意义. typedef struct{ //栈结点结构 保 ...
- 算法實例-C#-歸併排序-MergeSort
# 算法实例 # 排序算法Sort 歸併排序MergeSort 算法說明 歸併的思路是任意兩個元素可以比較大小,那麼任意兩個有序的元素集合也可以通過比較大小的方式歸併成一個有序的元素集合 任何的無序元 ...
- Tigase XMPP Server的安装
Tigase和OpenFire都是基于XMPP(Extensible Messaging and Presence Protocol, 可扩展通讯和表示协议)的,主要功能是实现消息的即时通信.Goog ...
- Malformed \uxxxx encoding解决方法
java.lang.IllegalArgumentException: Malformed \uxxxx encoding. at java.util.Properties.loadConvert(U ...
- Java集合源码分析(二)ArrayList
ArrayList简介 ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,类似于C语言中的动态申请内存,动态增长内存. ArrayList不是线程安全的,只能用在单线程环境下,多线 ...
- 【Effective Java】11、同步访问共享的可变数据
这段时间看的部分感觉没啥需要记录下来的,个人也没什么想法,不过以后还是要多记,多写 package cn.xf.cp.ch02.item66; import java.util.concurrent. ...
- Git远程和分支管理
一.远程 Git是分布式版本控制系统,最重要的优点就是远程仓库托管代码.不用自己搭建一个服务器,在github上面注册一个账户就可免费获取远程仓库. 首先需要先在github上面 ...
- Servlet生命周期及工作原理
1 Servlet生命周期Servlet 生命周期:Servlet 加载--->实例化--->服务--->销毁. init():在Servlet的生命周期中,仅执行一次init()方 ...
- sass的四种css编译风格
sass的改变编译风格的语句: sass style expanded assets/sass/style1.sass:assets/css/style1.css 1.nested:默认 #main ...