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 12300 - Smallest Regular Polygon
题意:给定两个点A和B,求包含这两个点的面积最小的正 n(已知)边形. #include<iostream> #include<iomanip> #include<cma ...
- C 函数 strstr 的高效实现
C函数库中有一个函数 strstr(char*, char*),它实现的是在一个原字符串中查找一个子串.假设找到这种一个子串,返回这个子串在原字符串中的起始位置,若没有找到这种一个子串.则 ...
- hdu 1387 Team Queue (链表)
题目大意: 不同的人在不同的队伍里,插入链表的时候假设这个链表里有他的队友,就把它放到最后一个队友的最后.假设没有队友,就把它放到整个链表的最后面. 出链表的时候把第一个人拿出来. 思路分析: 要模拟 ...
- [置顶] Vim用正则表达式进行批量修改
vim可以设置 magic 这个东西, magic就是设置哪些元字符要加反斜杠哪些不用加的. 简单来说: magic(\m):除了 $ . * ^ 之外其他元字符都要加反斜杠. nomagic(\M) ...
- Linux 多线程串口通信
大概流程就是打开一个串口.然后进行串口设置.开启二个线程,一个线程写数据,另一个线程读数据. 代码如下: #include <stdio.h> #include <stdlib.h& ...
- GrabCut--Opencv篇
最近因为工作需要,需要实现一个Grabcut函数.Opencv已经提供此函数,今天把opencv的例程拿出来跑了一下,对于简单的背景实现效果还不错. OpenCV中的GrabCut算法是依据<& ...
- EndNote是一款着名的参考文献管理软件
EndNote是一款着名的参考文献管理软件,我们可以通过该软件创建个人参考文献库,此外对公司DCC.法务和专 利部门十分的有用,甚至对我们写SOP 也有些帮忙,并且该软件可以在其中加入文本.图像.表格 ...
- timesten升级
ttIsql "DSN=ttwind;UID=cacheuser;PWD=cacheuser;OraclePWD=cacheuser;" --1.查看当前版本号 Command&g ...
- JSCapture实现屏幕捕捉
JSCapture 是用纯 JavaScript 和 HTML5 实现的屏幕捕捉库. 能够随意在浏览器或者桌面视频进行截图, JSCapture 使用 getUserMedia 来实现屏幕捕获. 当前 ...
- Android开发四大组件概述
这个文章主要是讲Android开发的四大组件,本文主要分为 一.Activity具体解释 二.Service具体解释 三.Broadcast Receiver具体解释 四.Content Provid ...