发送通知

public class MyActivity extends Activity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState); String serviceContextName = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager;
notificationManager = (NotificationManager) getSystemService(serviceContextName); //设置图标,标题,时间
int icon = R.drawable.ic_launcher;
String tickerText = "Notification";
long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when);
notification.number++; //设置展开通知的内容
Context context = getApplicationContext();
String expandedText = "Extended status text";
String expandedTitle = "Notification Title"; //当单击展开的文本时,用于启动一个活动的意图
Intent intent = new Intent(this, MyActivity.class);
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, expandedText, expandedText, launchIntent); //若要定制布局(若手动设置contentView时,必须同时设置contentIntent)
notification.contentView = new RemoteViews(this.getPackageName(), R.layout.my_status_window_layout);
notification.contentIntent = launchIntent; //修改通知中的视图
notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_launcher);//将后者搬到前者这个id的视图上
notification.contentView.setTextViewText(R.id.status_text, "Current Progress");
notification.contentView.setProgressBar(R.id.status_progress, 100, 50, false); //触发通知
int notificationRef = 1;
notificationManager.notify(notificationRef, notification); //消除通知
notificationManager.cancel(notificationRef); notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; //设置上默认的声音和震动 //自定义通知声音
Uri ringURI = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.sound = ringURI; //自定义通知震动,需添加一个permission <uses-permission android:name="android.permission.VIBRATE" />
long[] vibrate = new long[] {1000,1000,1000,1000,1000};//一个值震动多久,下一个值暂定多久,这里持续了5秒
notification.vibrate = vibrate; //自定义通知闪屏
notification.ledARGB = Color.RED;
notification.ledOffMS = 0;//设置频率
notification.ledOnMS = 1; //若OnMS也是0,则将灯关闭
notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS; //持续的通知
notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;//正在进行的事件
//连续的通知
notification.flags = notification.flags | Notification.FLAG_INSISTENT;//一直重复音频震动闪烁直到被取消
}
}

警报

public class MyActivity extends Activity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState); //警报。警报类型:
// RTC_WAKEUP指定时间唤醒并触发意图;
// RTC指定时间触发意图但不唤醒设备;
// ELAPSED_REALTIME设备启动后经过的时间触发待处理的意图,但不唤醒设备;
// ELAPSED_REALTIME_WAKEUP设备启动并经过指定时间后唤醒设备并触发意图
AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
int alarmType = AlarmManager.ELAPSED_REALTIME_WAKEUP;
long timeOrLengthofWait = 10000;
String ALARM_ACTION = "ALARM_ACTION";
Intent intentToFire = new Intent(ALARM_ACTION);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intentToFire, 0);
alarms.set(alarmType, timeOrLengthofWait, pendingIntent); //取消报警
alarms.cancel(pendingIntent); //重复报警
//如果已经唤醒,那么每小时触发一次意图
alarms.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 60*60*1000, 60*60*1000, pendingIntent);
//每小时唤醒并触发一个警报
alarms.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 60*60*1000, AlarmManager.INTERVAL_DAY, pendingIntent);
}
}

android-通知Notification的更多相关文章

  1. android通知-Notification

    android中,当app需要向发送一些通知,让使用者注意到你想要告知的信息时,可以用Notification.下面,就来讨论一下,Notification的用法,我们从实际的小例子来进行学习. 1. ...

  2. Android 通知(Notification)

    1.介绍 2.常用属性 3.java后台代码 package com.lucky.test30notification; import android.app.Notification; import ...

  3. Android通知Notification全面剖析

    通知 通知是您可以在应用的常规 UI 外部向用户显示的消息.当您告知系统发出通知时,它将先以图标的形式显示在通知区域中.用户可以打开抽屉式通知栏查看通知的详细信息. 通知区域和抽屉式通知栏均是由系统控 ...

  4. Android——通知 Notification

    链接:http://jingyan.baidu.com/article/77b8dc7fde875a6175eab641.html http://www.2cto.com/kf/201502/3749 ...

  5. Android中的通知—Notification 自定义通知

    Android中Notification通知的实现步骤: 1.获取NotificationManager对象NotificationManager的三个公共方法:①cancel(int id) 取消以 ...

  6. Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。

    常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...

  7. Android 状态栏通知Notification、NotificationManager简介

    Notification(通知)一般用在电话,短信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这个通知: 在Android系统中, ...

  8. Android的状态栏通知(Notification)

    通知用于在状态栏显示消息,消息到来时以图标方式表示,如下: 如果需要查看消息,可以拖动状态栏到屏幕下方即可查看消息. 1.Layout布局文件: <RelativeLayout xmlns:an ...

  9. Android简易实战教程--第三十八话《自定义通知NotifiCation》

    上一篇小案例,完成了一个普通的通知,点击通知启动了一个活动.但是那里的通知没有加入些"靓点",这一篇就给它加入自定义的布局,完成自定义的通知. 应用:比如QQ音乐为例,当点击音乐播 ...

  10. Android开发——Notification通知的各种Style详解

    本来是想与之前讲解使用Notification通知使用一起写的,查看了资料,觉得有必要将这Style部分单独拿出来讲解 前篇:Android开发——Notification通知的使用及Notifica ...

随机推荐

  1. 【转】sun.misc.BASE64Encoder找不到jar包的解决方法

    只需要在project build path中先移除JRE System Library,再添加库JRE System Library,重新编译后就一切正常了.(太神奇了,转自http://blog. ...

  2. 查询EBS在线用户SQL(R12)

    SELECT U.USER_NAME, APP.APPLICATION_SHORT_NAME, FAT.APPLICATION_NAME, FR.RESPONSIBILITY_KEY, FRT.RES ...

  3. UIPasteboard 粘贴板

    UIPasteboard *pasteboard = pasteboard.string = self.label.text;

  4. python 学习笔记 9 -- Python强大的自省简析

    1. 什么是自省? 自省就是自我评价.自我反省.自我批评.自我调控和自我教育,是孔子提出的一种自我道德修养的方法.他说:“见贤思齐焉,见不贤而内自省也.”(<论语·里仁>)当然,我们今天不 ...

  5. Linux网络管理——端口作用

    1. 网络基础 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB",&q ...

  6. [LeetCode]题解(python):154-Find Minimum in Rotated Sorted Array II

    题目来源: https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/ 题意分析: 给定一个有重复的翻转的数组,找到最 ...

  7. ORACLE同义词总结

    ORACLE同义词总结 同义词概念 Oracle的同义词(synonyms) 从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系.它可以节省大量的数据库空间,对不同用户的操作同一张表没有多 ...

  8. 柯南君:看大数据时代下的IT架构(4)消息队列之RabbitMQ--案例(Helloword起航)

    柯南君:看大数据时代下的IT架构(4)消息队列之RabbitMQ--案例(Helloword起航) 二.起航 本章节,柯南君将从几个层面,用官网例子讲解一下RabbitMQ的实操经典程序案例,让大家重 ...

  9. MFC DLL资源动态切换

    在MFC使用过程中,遇到DLL资源与主EXE资源冲突问题. 出现这样的Bug,一时无从下手. 报错位置在核心代码中dlgcore.cpp. [cpp] view plaincopy BOOL AFXA ...

  10. 调用父类Controller错误

    在写一个控制器的时候,要特别注意本类继承的父类.不要继承错了.如图: ,这样就会一直是显示父类的控制器,而不是显示本类的控制器视图. 应该改为: 这些都是平时遇到的一些小问题,留着提醒自己.