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. 这里不做那么花俏了,仅提供黑白两色.但能够改变笔尖的粗细. 实质上这里的 ...
随机推荐
- mysql基础:列类型--整型
mysql列类型--字符串 http://blog.csdn.net/jk110333/article/details/9342301 mysql列类型--时间和日期 http://blog. ...
- Firemonkey绑定对象列表
在实现Firemonkey绑定对象列表的过程中,我遇到的一些现有教程当中没有提到的细节,分享一下. 1.追加对象 用Navigator插入记录,位置总是在当前记录之前插入,没有在最后追加一个对象的方法 ...
- Hide C# winform App Window When Started by Task Scheduler
To make a Scheduled Task run in the background, change the User running the task to "SYSTEM&quo ...
- java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.<init>(L
关于错误: java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.&l ...
- 当try和finally里都有return时,会忽略try的return,而使用finally的return
今天去逛论坛 时发现了一个很有趣的问题: 谁能给我我解释一下这段程序的结果为什么是:2.而不是:3 代码如下: class Test { public int aaa() { int x = 1; t ...
- linux 终端控制-- 多彩输出 格式排版
linux 终端控制-- 多彩输出 格式排版 在unix/linux的终端下,怎么控制终端输出的颜色和格式呢,当然了有专门的工具,tput,但是能被terminal直接读懂的格式化字符串更通用. 先来 ...
- Java核心技术-高级特性(2)- SoftReference, WeakReference and PhantomReference
Java.lang.ref 是 Java 类库中比较特殊的一个包,它提供了与 Java 垃圾回收器密切相关的引用类.这些引用类对象可以指向其它对象,但它们不同于一般的引用,因为它们的存在并不防碍 Ja ...
- Advanced Data Structures
Advanced Data Structures Advanced Data Structures
- ArcSDE当关系查询ArcMap与REST查询结果不一致问题的解决
首先描述来形容什么问题: 周边环境:ArcGIS10.x.Oracle 11g R2,这个问题无关与环境 假设用户使用关联查询(比方一个空间数据与一个属性数据进行关联),在ArcGIS for Des ...
- TR90眼镜_百度百科
TR90眼镜_百度百科 TR90眼镜