如何创建前台Android Service
2016-04-09 20:12
579 查看
如何创建前台Android Service
代码
public class LocationService extends Service { @Override public void onCreate() { super.onCreate(); Resources res = getResources(); Notification.Builder builder = new Notification.Builder(getApplicationContext()); PendingIntent contentIndent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); builder .setContentIntent(contentIndent) .setSmallIcon(R.mipmap.ic_launcher)//设置状态栏里面的图标(小图标) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher))//下拉下拉列表里面的图标(大图标) .setTicker("在哪儿正在运行中") //设置状态栏的显示的信息 .setWhen(System.currentTimeMillis())//设置时间发生时间 .setAutoCancel(true)//设置可以清除 .setContentTitle("This is ContentTitle")//设置下拉列表里的标题 .setContentText("this is ContentText");//设置上下文内容 Notification notification = builder.build();//获取一个Notification startForeground(1,notification); }
相关文章推荐
- Android手势识别Demo
- [Android] 控件的动态显示和自动消失效果
- [Android] 设计模式-策略模式
- 《Android 开发艺术探索》读书笔记二 Activity的启动模式(launchMode)
- [Android] AIDL浅析
- 【Android学习】View点击事件的分发机制(一)
- Android选择器类库,包括日期时间选择器、单项选择器、地址选择器、颜色选择器、文件目录选择器、数字选择器、星座选择器等
- 结对编程--基于android平台的黄金点游戏
- 《Android 开发艺术探索》读书笔记一 Activity的生命周期
- Android View.setOnclickListener(),View.onTouchEvent(),View.setOnTouchListener()关系源码分析
- Android中的代理模式
- Android中的Service的使用详解
- Android 开发 上传用户头像到服务器的数据库再获取显示
- Android表格自定义控件
- Android 编码规范
- Android退出时创建弹窗对话框
- Android常见的几种RuntimeException
- android性能调优工具TraceView的使用
- 使用Bitmap遍历Assets目录下图片
- Android 中View的绘制机制源代码分析 三