- 浏览: 49338 次
文章分类
- 全部博客 (25)
- Android (19)
- startActivityForResult() (1)
- Intent (3)
- HTML (1)
- onCreate (1)
- Button (3)
- OnClick (3)
- Activity (2)
- savedInstanceState (1)
- Service (2)
- message (1)
- Notification (1)
- Broadcast (1)
- SQLite (1)
- SharePreferences (1)
- Galaxy 9300 (1)
- 刷机 (1)
- root (1)
- ContentProvider (1)
- 笔记本 (1)
- 散热 (1)
- 算法 (3)
- C (4)
- socket (0)
- java (0)
最新评论
Status Notification是作用是在页眉的位置,提示用户某一项操作已完成或者请求用户交互,当用户选择并点击后,会启动相应的操作。比如Service的下载任务完成,可以用此方法提醒用户;还有比如未接电话提示等等。
后台的Service不应该为了得到用户的交互去启动一项Activity,而应该生成一个Status Notification,当用户选择点击后,这个Status Notification去启动Activity。
一个Status Notification包含Status Bar和Notification Message两部分。
Activity和Service都可以初始化一个Status Notification。但是由于Activity只能处于前端且获得焦点才能执行动作,所以总是在Service中生成Status Notification。这样,Notification就可以在后台生成,比如用户在运行其他应用或者设备睡眠的时候。
生成Notification,需要用到两个类:Notification和NotificationManager。
package com.test.statusnotificationdemo; import android.os.Bundle; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.view.Menu; import android.view.MenuItem; import android.support.v4.app.NavUtils; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); //创建NotificationManager,这里并不是用New方法 //创建的mNotificationManager对象负责"发出"和"取消"notification NotificationManager mNotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); //这里是设置notification的bar,三个参数分别是在bar上显示的图标、信息、时间 Notification notification=new Notification(R.drawable.ic_launcher, "Hello", System.currentTimeMillis()); //PendingIntent是一个封装好的Intent,它并不立即执行,而且等待事件来触发 //Activity.this的context 返回当前activity的上下文,属于activity ,activity 摧毁他就摧毁 //getApplicationContext() 返回应用的上下文,生命周期是整个应用,应用摧毁它才摧毁 Context context=getApplicationContext(); CharSequence contextTitle="My notification"; CharSequence contextText="Hello World!"; Intent notificationIntent=new Intent(this,NotificaitionActivity.class); //PendingIntent 为Intent的包装,这里是启动Intent的描述,PendingIntent.getActivity 返回的PendingIntent表示,此PendingIntent实例中的Intent是用于启动 Activity 的Intent。 PendingIntent contentIntent=PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contextTitle, contextText, contentIntent);//四个参数分别为:所在的Activity或application、详细信息Title、详细信息内容Text、相应的Intent //用mNotificationManager发出notification int HELLO_ID=1;//用于notification的标识 mNotificationManager.notify(HELLO_ID, notification); } }
发表评论
-
ContentProvider
2012-08-09 14:43 798ContentProvider学习笔记 ContentPro ... -
Galaxy 9300 刷机和获取root权限
2012-08-08 14:19 1571刷机和ROOT是两个不同但是很类似的动作。 刷机应该就 ... -
SharedPreferences 存储
2012-07-27 20:02 893SharedPreferences是Android平台 ... -
SQLite 存储
2012-07-27 10:33 769SQLite是一种轻量级的,嵌入式的数据库系统,它占用的资源非 ... -
Android Broadcast 广播
2012-07-23 10:47 854从现实生活中理解广播机制 一听到广播我们第一感觉就会联 ... -
Android Message机制
2012-07-20 11:01 1173参考链接http://www.cnblogs.com/hnra ... -
Android Service之bindService()
2012-07-17 14:37 1152http://www.cnblogs.com/onlylitt ... -
Android Service 之StartService()
2012-07-17 10:25 11768Service是android 系统中的一种组件,它跟Acti ... -
Activity_savedInstanceState
2012-07-14 10:31 3969假设有两个Activity,分别是MainActivity,S ... -
Activity生命周期
2012-07-13 11:24 705Activity的生命周期图如上所示 用一个实例来测试 ... -
ButtonDemo_OnClick_2
2012-07-13 00:47 600public void onCreate(Bundle ... -
intentDemo_2
2012-07-13 00:45 729<manifest xmlns:android=& ... -
intentDemo_1
2012-07-13 00:45 583package com.test.intentdemo; ... -
ButtonDemo_OnClick_3
2012-07-13 00:45 579package com.test.buttondemo; ... -
ButtonDemo_OnClick_1
2012-07-12 22:51 796public class MainActivity ex ... -
Android开发——关于onCreate的解读
2012-07-12 22:48 590在AndroidManifest.xml文件中的< ... -
startActivityForResult()的用法
2012-07-12 22:43 1592参考链接:http://www.cnblogs.com/mub ... -
Intent传递数据从一个Activity到另一个Activity
2012-07-12 21:19 11805MainActivity package com.te ...
相关推荐
AgentLight是用于Avaya联系中心的座席状态通知的软件。 该软件与USB照明设备集成在一起,并通过打开或闪烁不同颜色的设备来显示座席状态。 例如,该软件可以配置为以绿色显示座席空闲和正在呼叫时显示红色。
Version 0.9.2 - Fixed: problem with "RAM Status Notification" screen and other small issues 【使用方法】直接复制到PDA中,安装和运行。去掉官方语言文件,采用核心汉化。 【特别提示】CAB和绿色 =====...
隐藏Android4.0及以上版本的ActionBar、NotificationBar、StatusBar、SystemBar、TitleBar
介绍了StatusBar中Notification的使用方法,以及如何添加状态栏系统图标。
"在窗口顶端或者下端弹出自定义的提示视图(notification View)。例如,图中上方的黑色标签“This is the notification.""。可用于显示当前app的状态,用户操作的提示等等。" 注意:请在Mac下解压使用
语言:English 当Github状态检查通过或失败时,向您发送桌面通知 而不是在等待检查通过时进行其他操作,而只是忘记了它们,而是意识到一个讨厌的空白问题将其破坏了,而是使用此扩展功能,在检查通过或失败后立即获得...
源码CWStatusBarNotification,CWStatusBarNotification是一个创建在状态栏上显示文字Notification的iOS类库,在StatusBar上面覆盖文字Notification,可以自定义Notification持续出现的时长。当Notification出现时,...
监听网络变化(Network status changed notification: (WWAN)2G,3G,4G,Wi-Fi,Not reachable) ####Requirements Minimum iOS Target iOS 7 #####添加 Framework CoreTelephony.framework #####添加下面这些文件: ...
notification发送演示小demo。
IOS应用源码之【应用】StatusNotifier-iPhone Email, SMS, MMS, IM, Call, Voicemail notification in status bar
正在翻译通知中心可以通过Transifex进行翻译: : 添加自己的通知类型// config.php$ GLOBALS [ 'NOTIFICATION_CENTER' ][ 'NOTIFICATION_TYPE' ][ 'isotope' ] = array( // Type 'iso_order_status_change' => array...
Download and install into your phone and enjoy it ! Tip: Runningman Phone List Database 2.0.08 Features : ...- set or view status (status shown on the top screen) - skinnable (4 type skins)
在窗口状态栏(UIStatusBar)顶端或者下端弹出自定义的提示视图(notification View)。例如,图中上方的黑色标签“This is the notification."。可用于显示当前app的状态,用户操作的提示等等。 Code4App编译测试...
retain_status_information 1 保存主机状态信息 retain_nonstatus_information 1 is_volatile 0 check_period 24x7 检查周期 max_check_attempts 3 最大重试次数 normal_check_interval 10 普通检查间隔 ...
• 使用Networkstatus来显示当前手机网络的状态 • 创建一个SL应用程序,用来注册pushnotificationservices(包括token和toast) ◦ 运行期控制push事件events(token,toast,和raw) ◦ 在Shell中显示token和toast信息 ...
Notification Listener Service 3.8.3.3. DND (Do not Disturb) 3.8.4. Search 3.8.5. Alerts and Toasts 3.8.6. Themes 3.8.7. Live Wallpapers 3.8.8. Activity Switching 3.8.9. Input Management 3.8.10. Lock ...
SystemUI:StatusBar,Notification,PowerUI,SettingsUI,Recents,RingtonePlayer..
用开源时间@ 构建安装$ npm install com.nrswolf.cordova.push-notifications-status用法PushNotificationsStatus . isPushNotificationsEnabled ( function ( response ) { console . log ( 'Success: ' + ...
Status Bar Notification Source Code for Linux.
You'll get a push notification when it finishes along with the exit status. Installation Terminal watcher has two parts: A desktop client and an android app. To install the desktop client: (OS X and ...