013.statusBar-通知栏(Notification)
发表日期:2015-09-26 10:32:09 | 来源: | | 浏览(693) 分类:Android杂项
MainActivity:
protected void onStart() { Toast.makeText(MainActivity.this, "onStart", Toast.LENGTH_SHORT).show(); super.onStart(); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //取消通知栏 manager.cancel(R.layout.activity_main); }
StatusBarService.java
package com.example.StatusBar; import android.app.IntentService; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; public class StatusService extends IntentService { //private static final int KUKA = 0; public StatusService() { super("StatusService"); // TODO Auto-generated constructor stub } @Override protected void onHandleIntent(Intent intent) { showNotification(false); //模拟耗时操作 try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } showNotification(true); } @SuppressWarnings({ "deprecation" }) private void showNotification(boolean finish) { //通知栏消息 Notification notification; //消息管理器 NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); //当用户点击消息的时候显示那个activity Intent intent = new Intent(this, MainActivity.class); //将要发生的意图 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); if (finish) { notification = new Notification(R.drawable.ic_launcher, "文件下载完成", System.currentTimeMillis()); notification.setLatestEventInfo(this, "文件下载完成", "没有新任务", contentIntent); }else { notification = new Notification(R.drawable.ic_launcher, "文件开始下载", System.currentTimeMillis()); notification.setLatestEventInfo(this, "文件正在下载中", "请稍候...", contentIntent); } manager.notify(R.layout.activity_main, notification); } }
- Android(0)
- Android基础(0)
- Android杂项(22)
- 安卓生命周期(0)
- android安卓支持的所有传感器Sensor列表及类型值常量(0)
- 013.statusBar-通知栏(Notification)(0)
- 001.android开发-Activity(活动)(0)
- android studio 快捷键(0)
- android 常用代码集锦(0)
- ADB 指令大全(0)
- Android manifest.xml 中元素含义(0)
- Android 动态关闭Manifest中的Receiver的方法(0)
- AndroidManifest.xml文件综合详解(0)
- AndroidManifest.xml元素含义介绍(0)
- Android的AndroidManifest.xml文件介绍(0)
- Android 文件类型和MIME的匹配表(0)
- Android SDK中tools详解(0)
- Android SDK 目录和作用详解(0)
- Android Apk文件结构简介(0)
- Android中的库(0)
- Manifest.permission_group android所有授权常量2(0)
- Manifest.permission android所有授权常量(0)
- 判断内存卡是否存在,获取内存卡根目录地址(0)
- 控件所有属性(0)
- 字符串滚动(0)