发送通知

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. cookie的expires属性和max-age属性

    expires属性 指 定了coolie的生存期,默认情况下coolie是暂时存在的,他们存储的值只在浏览器会话期间存在,当用户推出浏览器后这些值也会丢失,如果想让 cookie存在一段时间,就要为e ...

  2. utf8+bom格式保存php curl乱码问题

    今天开发遇到一个php curl取数据乱码问题 不是gzip也不是编码设置问题 最后有一同事判断为utf8+bom保存数据原因,懒得深入了解utf8+bom,仅做记录 [root@centos5 ~] ...

  3. leetcode Letter Combinations of a Phone Number python

    class Solution(object): def letterCombinations(self, digits): """ :type digits: str : ...

  4. GoF——职责链模式

    职责链模式(chain of Responsibility):使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它 ...

  5. DRAM与NAND Flash产业六大趋势预测分析

    集邦科技(TrendForce)旗下的分析部门DRAMeXchange的研究,针对对DRAM与NANDFlash产业的长久观察下,提出了对2012-2015年间产业发展的六大趋势预测:     趋势一 ...

  6. 苹果新专利详解Apple Pay和NFC工作原理

    本周,美国专利商标局公布了苹果一项名为“在移动支付过程中调节NFC的方法”专利申请.专利文件中详细描述了苹果Apple Pay功能以及NFC硬件构架和工作模式. 首先,苹果在专利文件中介绍了其无接触支 ...

  7. ViewPager实现页卡的最新方法--简洁的TabLayout(谷歌支持包)

    效果图: 添加依赖包: compile ‘com.android.support:design:‘ 布局文件: <?xml version="1.0" encoding=&q ...

  8. 编程珠玑I算法总结

    主要是根据编程珠玑后面的Algorithm附录总结了一下这本书里面的经典算法. 1 辗转相减求最大公约数 思想:最大公约数能整除i和j,则其一定也能整除i-j(if i>j) int gcd(i ...

  9. centos6 qt ENV

    打算做嵌入式图像处理,计划方案嵌入式Linux+OpenCV+QT,昨天简单入门OpenCV今天看看QT,QT就先弄Linux下面的,回家之前争取把基本的摸通,然后能在板子上跑起来 关于QT安装 QT ...

  10. freemaker

    FreeMarker模板文件主要由如下4个部分组成:  1,文本:直接输出的部分  2,注释:<#-- ... -->格式部分,不会输出  3,插值:即${...}或#{...}格式的部分 ...