Android中的前置服务
来源:互联网 发布:excel如何去重复数据 编辑:程序博客网 时间:2024/05/20 22:39
在服务中有这个方法,可以绑定一个Notification,启动一个前置服务,就像金山软件那样,
void android.app.Service.startForeground(int id,Notification notification)
private void setUpAsForeground(String text,Class cls) {
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, new Intent(getApplicationContext(),
cls), PendingIntent.FLAG_UPDATE_CURRENT);
mNotification = new Notification();
mNotification.tickerText = text;
mNotification.icon = R.drawable.logo;// TODO 更换服务前置的图标
mNotification.flags = Notification.FLAG_ONGOING_EVENT;
mNotification.icon = R.drawable.logo;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification.setLatestEventInfo(getApplicationContext(), "", text,
pendingIntent);
startForeground(NOTIFICATION_ID, mNotification);
}
stopForeground(true);//停止一个前置服务 在项目中关于消息的前置服务,遇到了一个问题!当我在任何一个页面按home键时,都要启动前置服务,点击进入页面之后,就需要停止前置服务。要实现qq中的消息效果,可我们的项目中有多个页面,无法实现qq中的效果,最后就搞了一个父类,让用到的这多个activity都继承自父类,然后在父类的生命周期的方法中,对前置服务的的启动与停止做了处理,让每个子类在执行完自己的生命周期方法后,在执行以下父类的,这样,这个问题就解决了。
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, new Intent(getApplicationContext(),
cls), PendingIntent.FLAG_UPDATE_CURRENT);
mNotification = new Notification();
mNotification.tickerText = text;
mNotification.icon = R.drawable.logo;// TODO 更换服务前置的图标
mNotification.flags = Notification.FLAG_ONGOING_EVENT;
mNotification.icon = R.drawable.logo;
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotification.setLatestEventInfo(getApplicationContext(), "", text,
pendingIntent);
startForeground(NOTIFICATION_ID, mNotification);
}
- Android中的前置服务
- Notification通知 前置服务
- C++中的前置声明
- C++中的前置声明
- c++中的前置声明
- Android 调用前置摄像头
- Android 调用前置摄像头
- Android 调用前置摄像头
- Android 调用前置摄像头
- android 前置service
- android opencv 前置摄像头
- android中的本地服务
- Android中的服务生命周期
- android中的服务---Service
- Android 中的服务总结
- Android中的系统服务
- 关于C++中的前置声明
- 关于C++中的前置声明
- android之简单手电筒
- ACM2012长春赛区网络赛——1010
- ubuntu输入正确密码后又跳回到登录界面
- could not find adb.exe
- 替代three20的一个框架
- Android中的前置服务
- 浅谈web指纹识别技术
- poll 的例子
- 求两个字符串的最长公共子串
- 指针常见定义
- 求两个字符串最长公共子串(LCS问题) 两种思想
- ACM2012长春赛区网络赛——1011
- js 逻辑运算&& ||
- 浅谈网络营销