Android-它们的定义Notification
package com.wwj.custom.notification; import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
* 自己定义Notification
*
* @author wwj
*
*/
public class MainActivity extends Activity implements OnClickListener { private Button showNotification;
private Button showCustomNotifi; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); showNotification = (Button) findViewById(R.id.button1);
showCustomNotifi = (Button) findViewById(R.id.button2); showNotification.setOnClickListener(this);
showCustomNotifi.setOnClickListener(this); } @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
send();
break;
case R.id.button2:
custom();
break; default:
break;
}
} /**
* 旧方法
*/
public void send() {
// 1 得到通知管理器
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // 2构建通知
Notification notification = new Notification(
android.R.drawable.stat_notify_chat, "这是提示信息",
System.currentTimeMillis()); // 3设置通知的点击事件
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 100,
intent, 0);
notification.setLatestEventInfo(this, "通知的标题", "通知的内容", contentIntent); notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知之后自己主动消失 // 4发送通知
nm.notify(100, notification);
} /**
* 自己定义Notification 新方法
* 新的方法,本人在手机測试会崩溃,假设不行的话,能够继续使用旧的构建方法,毕竟高版本号会兼容低版本号的
*/
public void custom() {
// 1 得到通知管理器
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// 2 设置通知的点击事件
Intent intent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 100,
intent, 0);
// 3构建通知
Notification.Builder builder = new Notification.Builder(this)
// API 11加入的方法
.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon)
// 设置状态栏的小标题
.setLargeIcon(
BitmapFactory.decodeResource(getResources(),
R.drawable.jay))// 设置下拉列表里的图标
.setWhen(System.currentTimeMillis()).setTicker("凤姐来啦")// 设置状态栏的显示的信息
.setAutoCancel(true)// 设置能够清除
.setContentTitle("通知通知") // 设置下拉列表里的标题
.setContentText("凤姐即将光临天拓游戏,各部门做好防雷准备"); // 设置能够清除
Notification notification = builder.build();// API 16加入创建notification的方法
// 通知
manager.notify(110, notification); // // 2构建通知
// Notification notification2 = new Notification(R.drawable.jay, "天拓游戏",
// System.currentTimeMillis());
//
// // 3设置通知的点击事件
// Intent intent2 = new Intent(this, MainActivity.class);
// PendingIntent contentIntent2 = PendingIntent.getActivity(this, 100,
// intent2, 0);
// notification2.setLatestEventInfo(this, "天拓游戏", "天拓游戏有个技术部",
// contentIntent2);
//
// notification2.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知之后自己主动消失
//
// // 4发送通知
// manager.notify(100, notification2);
}
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
Android-它们的定义Notification的更多相关文章
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
- 第13讲- Android之消息提示Notification
第13讲 Android之消息提示Notification .Notification Notification可以理解为通知的意思一般用来显示广播信息,通知可以显示到系统的上方的状态栏(status ...
- Android新旧版本Notification
Android新旧版本Notification 在notification.setLatestEventInfo() 过时了 以前: NotificationManager mn = (Notific ...
- [Android Tips] 9. framework notification layout font size
android 4.4 framework notification layout 相关字体大小 * title: notification_title_text_size: 18dp * conte ...
- Android记录4--自定义ToggleButton+用SharedPreferences保存用户配置
Android记录4--自定义ToggleButton+用SharedPreferences保存用户配置 2013年8月14日Android记录 很多应用都会有用户设置,用户的一些偏好可以由用户来决定 ...
- Android 使用shape定义不同控件的的颜色、背景色、边框色
Android 使用shape定义不同控件的的颜色.背景色.边框色 设置按钮的右边框和底边框颜色为红色,边框大小为3dp: 在drawable新建一个 buttonstyle.xml的文件,内容如下: ...
- Android peferenceActivity 自己定义标题简单方法
Android peferenceActivity 自己定义标题简单方法 peferenceActivity 全然使用定义好的布局. 因此不能简单象其他好窗体进行自定,如今我们须要加 一个自己定义标题 ...
- Android各分辨率定义的图片规格
我们定义的app图片规格 app图标需要分iphone和android两套 iphone: 名称 Iphone4 Iphone5 手机尺寸 960*640(高*宽) 1136*640 (高*宽) 电池 ...
- 【Android】自己定义View、画家(画布)Canvas与画笔Paint的应用——绘图、涂鸦板app的实现
利用一个简单的绘图app来说明安卓的图形处理类与自己定义View的应用. 例如以下图,有一个供用户自己随意绘图.涂鸦的app. 这里不做那么花俏了,仅提供黑白两色.但能够改变笔尖的粗细. 实质上这里的 ...
随机推荐
- JavaScript常用全局属性与方法
最近,在学习JavaScript,Java作域链包含全局,记录下常用的全局属性与方法,就当是知识的积累,未列出全部,如需查看全部可参考JS相关的API文档. 常用的全局属性: 全局属性 作 ...
- 从源代码角度分析ViewStub 疑问与原理
一.提出疑问 ViewStub比較简单.之前文章都提及到<Android 性能优化 三 布局优化ViewStub标签的使用>.可是在使用过程中有一个疑惑,究竟是ViewStub上设 ...
- 纯JS实现的3D标签云,不依赖不论什么第三方库,支持移动页面
<span style="font-family: Arial, Helvetica, sans-serif;"><!DOCTYPE html PUBLIC &q ...
- 在Delphi中使用C++对象(两种方法,但都要改造C++提供的DLL)
Delphi是市场上最好的RAD工具,但是现在C++占据着主导地位,有时针对一个问题很难找到Delphi或Pascal的解决方案.可是却可能找到了一个相关的C++类.本文描述几种在Delphi代码中使 ...
- 用Delphi画圆角Panel的方法(使用CreateRoundRectRgn创造区域,SetWindowRgn显示指定区域)
用Delphi画圆角Panel的方法: procedure TForm1.Button5Click(Sender: TObject);var fhr :Thandle;beginfhr:=Create ...
- js中获取jsp中的参数
碰到一个问题需要再js中根据jsp中request的参数判断执行那段代码 第一种写法: if('${method}'=="add"){js代码段1}else{js代码段2} 第二种 ...
- HTML5调用摄像头实现拍照功能(兼容各大主流浏览器)
本人亲測,兼容各大主流浏览器,HTML5太强大了,须要的留下邮箱哦 假设想要立即收到,则可到我的资源下载 http://download.csdn.net/detail/laijieyao/81699 ...
- 应届GIS硕士求职经验总结
记录一下作为一个GIS应届毕业生在帝都找工作的历程吧,之后的经历可能丰富多彩,可能萎靡不振,但这一次走过来了就是这一次的.希望以史为鉴,各位客官也能有所收获. 定位 我们这一届的"烟酒生&q ...
- IE与FF脚本兼容性问题
(1) window.event: 表示当前的事件对象,IE有这个对象,FF没有,FF通过给事件处理函数传递事件对象 (2) 获取事件源 IE用srcElement获取事件源,而FF用target获取 ...
- 【VB/.NET】Converting VB6 to VB.NET 【Part II】【之四】
第四部分 原文 DLLs, DAO, RDO, ADO, and AD.NET; the History of VB DBs In the early versions of VB, there we ...