- 1、本文档共9页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Notification 使用详解(很全)
Java android?2011-01-25 14:23:21
当用户有没有接到的电话的时候,Android顶部状态栏里就会出现一个小图标。提示用户有没有处理的快讯,当拖动状态栏时,可以查看这些快讯。Android给我们提供了NotificationManager来管理这个状态栏。可以很轻松的完成。? ? 如果要添加一个Notification,可以按照以下几个步骤1:获取NotificationManager:NotificationManager m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);2:定义一个Notification:??Notification??m_Notification=new Notification();3:设置Notification的各种属性://设置通知在状态栏显示的图标m_Notification.icon=R.drawable.icon;? ?? ?? ?? ?? ??//当我们点击通知时显示的内容m_Notification.tickerText=Button1 通知内容.....;? ?? ?? ?? ?? ?? ?? ?? ?? ?? ???通知时发出的默认声音m_Notification.defaults=Notification.DEFAULT_SOUND;//设置通知显示的参数Intent? ?m_Intent=new Intent(NotificationDemo.this,DesActivity.class);? ?? ??PendingIntent m_PendingIntent=PendingIntent.getActivity(NotificationDemo.this, 0, m_Intent, 0);m_Notification.setLatestEventInfo(NotificationDemo.this, Button1, Button1通知,m_PendingIntent );//这个可以理解为开始执行这个通知m_NotificationManager.notify(0,m_Notification);4:既然可以增加同样我们也可以删除。当然是只是删除你自己增加的。??m_NotificationManager.cancel(0);? ????这里的0是一个ID号码,和notify第一个参数0一样。这也就完成了,添加删除工作。这里我们还是一个Demo来掩饰我们的操作。1:新建一个工程NotificationDemo。2:添加一个Activity:DesActivity,注意需要在Manifest.xml中声明3:NotificationDemo中的Laytout文件很简单就是定义一个Button.其代码文件如下:
package com.rocky.studio.ch4221;
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;
import android.widget.TextView;
public class NotificationDemo extends Activity {
Button m_Button1;
TextView m_txtView;
NotificationManager m_NotificationManager;
Notification m_Notification;
Intent m_Intent;
PendingIntent m_PendingIntent;
??
? ? /** Called when the activity is first created. */
? ? @Override
? ? public void onCreate(Bundle savedInstanceState) {
? ?? ???super.onCreate(savedInstanceState);
? ?? ???setContentView(R.layout
文档评论(0)