博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android学习第十五天----notification应用
阅读量:4641 次
发布时间:2019-06-09

本文共 2114 字,大约阅读时间需要 7 分钟。

l通过一个按钮点击,然后在在通知栏显示通知信息;

package cn.core.test;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.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity implements OnClickListener {    private Button button1 = null, button2 = null;    private NotificationManager mNotificationManager = null;                 @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        button1 = (Button) findViewById(R.id.button1);        button1.setOnClickListener(this);                button2 = (Button) findViewById(R.id.button2);        button2.setOnClickListener(this);    }    @Override    public void onClick(View v) {        if(v==button1)        {//            Notification mNotification = new Notification();//            mNotification.icon=;//            mNotification.tickerText=;//            mNotification.when=;//                                    Notification mNotification = new Notification(                    android.R.drawable.presence_online, "通知",                    System.currentTimeMillis());                mNotification.defaults = Notification.DEFAULT_VIBRATE;                Intent intent = new Intent(MainActivity.this, Activity01.class);                PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,                    intent, 0);                mNotification.setLatestEventInfo(this, "开会通知11", "通知您下午17:60分在卫生间开会",                    pendingIntent);                mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);                mNotificationManager.notify(11111, mNotification);        }        else if(v==button2)        {            mNotificationManager.cancelAll();                    }                                                            }}

 

转载于:https://www.cnblogs.com/will-peng/archive/2013/03/25/2981652.html

你可能感兴趣的文章
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
Linux Supervisor的安装与使用入门
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>
ASP.NET MVC Identity 兩個多個連接字符串問題解決一例
查看>>