`
ko8e
  • 浏览: 50494 次
  • 性别: Icon_minigender_1
  • 来自: 龙岩
社区版块
存档分类
最新评论

Android控件之-Notification

阅读更多

状态栏提示

package com.ko8e;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MyActivity extends Activity {
	/** Called when the activity is first created. */
	private Button button = null;
	private Notification notification = null;
	private NotificationManager notificationManager = null;
	private PendingIntent pendingIntent = null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
		button = (Button) findViewById(R.id.button1);
		Intent intent = new Intent();
		intent.setClass(MyActivity.this, OtherActivity.class);
		pendingIntent = PendingIntent.getActivity(MyActivity.this, 0, intent, 0);
		notification = new Notification();
		
		button.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View arg0) {
				notification.icon = R.drawable.msn_thumb;
				notification.tickerText = "BUTTON通知内容········";
				notification.defaults = Notification.DEFAULT_SOUND;
				notification.setLatestEventInfo(MyActivity.this, "button", "Button通知 ", pendingIntent);
				notificationManager.notify(0, notification);
			}
		});
		
	}
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent">
	<Button
		android:id="@+id/button1"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:text="BUTTON"
		/>
</LinearLayout>

 

分享到:
评论

相关推荐

    Android高级编程--源代码

     由于Android构建在开源代码的框架之上,而且提供了强大的SDK库和开放的理念,所以它为广大的没有任何移动应用程序开发经验的新手开辟了一条开发完美的移动应用程序的康庄大道。而富有经验的移动开发人员现在也可以...

    Android开发中的Notification应用

    本实例描述的Android开发中的Notification通知控件的应用,包括通知的创建、属性设置、跳转方法以及删除等。希望能给学习Notification通知的朋友带来帮助。

    android服务自启动Service以及BroadcastReceiver和Notification

    android service Notification BroadcastReceiver Intent 安装的服务开机自启动,service定时的打印消息,消息同时显示在通知栏,窗体界面的跳转,自定义控件的开发。系统广播,定时广播,轮询广播等。...

    新版Android开发教程.rar

    ----------------------------------- Android 编程基础 1 封面----------------------------------- Android 编程基础 2 开放手机联盟 --Open --Open --Open --Open Handset Handset Handset Handset Alliance ...

    android开发资料大全

    android控件的抖动效果 很漂亮的ListView android 图像处理滤镜 照亮边缘特效 无闪烁启动画面 Android实现《天女散花》效果--(带源码) 天天动听 半透明Menu效果 Android 小項目之---Iphone拖动图片特效 (附源码) ...

    android开发入门与实战(下)

    7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...

    Android高薪之路:Android程序员面试宝典 李宁

    《Android高薪之路:Android程序员面试宝典》目录: 第1章 Android入门 1 1 关于Android的非技术问题 1 1 1 为什么看好 Android 1 1 2 以前是否从事过Android的工作 做过哪些工作 1 1 3 你做的最复杂的界面是什么 1 ...

    Android Studio目前所学习的9个控件代码

    Android Studio目前所学习的9个控件代码 后续随着学习进度还会不断更新 TextView Button EditText ImageView ProgressBar Notification Toolbar AlertDialog PopupWindow

    android-term-project

    #android-term-project 期末考试时间为:2018年6月19日, 随堂开卷测试; 测试范围包括,但不限于: Activity, Fragment生命周期; layout诸多控件及其属性与方法; Activity Result 异步处理; Volley; Sqlite与Json; ...

    Android应用开发揭秘pdf高清版

    4.2.21 状态栏提示(Notification、NotificationManager) 4.2.22 对话框中的进度条(ProgressDialog) 4.3 界面布局 4.3.1 垂直线性布局 4.3.2 水平线性布局 4.3.3.相对布局(RelativeLayout) 4.3.4 表单布局...

    《Android开发案例驱动教程》

    目 录 出版说明 前言 ...第14章 Broadcast Receiver和Notification 422 第15章 云端应用 449 第16章 Google Map和定位服务 487 第17章 Android通信应用开发 536 本章总结 592 附录 缩略语 参考文献

    android开发揭秘PDF

    4.2.21 状态栏提示(Notification、NotificationManager) 4.2.22 对话框中的进度条(ProgressDialog) 4.3 界面布局 4.3.1 垂直线性布局 4.3.2 水平线性布局 4.3.3.相对布局(RelativeLayout) 4.3.4 表单布局...

    《Android开发案例驱动教程》源码

    《Android开发案例驱动教程》部分源码 ...第14章 Broadcast Receiver和Notification 422 第15章 云端应用 449 第16章 Google Map和定位服务 487 第17章 Android通信应用开发 536 本章总结 592 附录 缩略语 参考文献

    Android开发案例驱动教程 配套代码

    《Android开发案例驱动教程》 配套代码。 注: 由于第12,13,14章代码太大,无法上传到一个包中。 这三节代码会放到其他压缩包中。 作者:关东升,赵志荣 Java或C++程序员转变成为Android程序员 采用案例驱动模式...

    《Android高级编程》

    4.2 View简介 4.2.1 使用View创建Activity(活动)用户界面 4.2.2 Android Widget工具箱 4.3 布局简介 4.4 创建新的View 4.4.1 修改现有的View 4.4.2 创建复合控件 4.4.3 创建定制的Widget和控件 4.4.4 使用定制的控件...

    详解Android中Notification的使用方法

    在消息通知的时候,我们经常用到两个控件Notification和Toast。特别是重要的和需要长时间显示的信息,用Notification最合适不过了。他可以在顶部显示一个图标以标示有了新的通知,当我们拉下通知栏的时候,可以看到...

    android群雄传

    第3章 Android控件架构与自定义控件详解 32 3.1 Android控件架构 33 3.2 View的测量 34 3.3 View的绘制 37 3.4 View Group的测量 38 3.5 View Group的绘制 39 3.6 自定义View 39 3.6.1 对现有控件进行拓展 40...

    Android高级编程.pdf

    第1章 Android简介 1.1 一些背景信息 1.1.1 不远的过去 1.1.2 未来的前景 1.2 对Android的误解 1.3 开放的移动开发平台 1.4 自带的Android应用程序 1.5 Android SDK功能 1.5.1 对包括摄像头、GPS和加速计在内的硬件...

    《Android应用开发揭秘》附带光盘代码.

    《Android应用开发揭秘》全部实例源代码,配合《Android应用开发揭秘》使用 前言  第一部分 准备篇  第1章 Android开发简介  1.1 Android基本概念  1.1.1 Android简介  1.1.2 Android的系统构架  1.1.3 ...

Global site tag (gtag.js) - Google Analytics