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. 这里不做那么花俏了,仅提供黑白两色.但能够改变笔尖的粗细. 实质上这里的 ...
随机推荐
- uva 11732 - strcmp() Anyone? 不错的Trie题
题解:http://blog.csdn.net/u013480600/article/details/23122503 我的代码一直TLE,,,看了人家的之后,认为1.链式前向星比較好,2.*dept ...
- sap的示例代码
sap的示例代码查看1.在SE38环境下的程序名输入栏输入'DEMO*'后按F4,你可以查到SAP所有的DEMO示例程序,好好看看,你会学到很多ABAP功能的实现方法.2.运行“ABAPDOCU”T- ...
- C++ Map 容器
1.Map是c++的一个标准容器,它提供了很好一对一的关系. Map是一种关联是容器,在map中增加和删除元素非常容易.可以修改一个特定的节点而不对其他节点不产生影响,由于map是一种关联式容器,Ke ...
- Linux Shell常用技巧(二) grep
七. grep家族: 1. grep退出状态: 0: 表示成功: 1: 表示在所提供的文件无法找到匹配的pattern: 2: 表示参数中提供的文件不存在. 见如 ...
- c/c++ 直接使用动态库 dlopen
c/c++ 直接使用动态库 dlopen 把各个版本编译成动态库,××.so ,提供统一的接口进行调用.这里使用的工具是dlxx系列函数 dlopen void *dlopen(const char ...
- perl的一些基本用法
ReadLine support available (try 'install Bundle::CPAN')cpan>进入cpan的shell,好了,我为了安装spamassassin,需要安 ...
- LV在系统重启后不能自动激活(boot.lvm&after.loca)
同类相关文章:http://blog.csdn.net/laven54/article/details/9121661 最近发现suse11sp2的系统解决了异常死机的问题之后,又引入了另外的问题,比 ...
- Qt4在linux下的安装
1.下载SDK ftp://ftp.informatik.hu-berlin.de/pub/Mirrors/ftp.troll.no/QT/qtsdk/qt-sdk-linux-x86-opensou ...
- python 循环中的else
众多语言中都有if else这对条件选择组合,但是在python中还有更多else使用的地方,比如说循环for,或者while都可以和else组合. 下面简单介绍一下for-else while-el ...
- 网络编程API-上 (基本API)
htons.ntohs.htonl和ntohl函数 Linux提供了4个函数来完毕主机字节序和网络字节序之间的转换 #include <netinet/in.h> uint16_t hto ...