|
|
@@ -63,22 +63,6 @@ public class ListenerShotNewService extends Service {
|
|
|
if (intent != null) {
|
|
|
userId = intent.getStringExtra(EXTRA_KEY_USER_ID);
|
|
|
}
|
|
|
- if(runningTaskUtil == null) {
|
|
|
- //初始化获取当前应用的工具类
|
|
|
- runningTaskUtil = new RunningTaskUtil(getApplicationContext());
|
|
|
- }
|
|
|
- if(manager == null) {
|
|
|
- //开启监听
|
|
|
- manager = ScreenShotListenManager.newInstance(getApplicationContext());
|
|
|
- manager.setListener(
|
|
|
- new ScreenShotListenManager.OnScreenShotListener() {
|
|
|
- public void onShot(String imagePath) {
|
|
|
- addPng(imagePath);
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- manager.startListen();
|
|
|
- }
|
|
|
|
|
|
|
|
|
int msgId = 113922;
|
|
|
@@ -110,7 +94,24 @@ public class ListenerShotNewService extends Service {
|
|
|
.build();
|
|
|
notification.flags |= Notification.FLAG_NO_CLEAR;
|
|
|
//这里的id不能是0
|
|
|
+ // android 8.0 Context.startForegroundService() 函数将启动一个前台服务。现在,即使应用在后台运行,系统也允许其调用 Context.startForegroundService()。不过,应用必须在创建服务后的五秒内调用该服务的 startForeground() 函数
|
|
|
startForeground(msgId, notification);
|
|
|
+ if(runningTaskUtil == null) {
|
|
|
+ //初始化获取当前应用的工具类
|
|
|
+ runningTaskUtil = new RunningTaskUtil(getApplicationContext());
|
|
|
+ }
|
|
|
+ if(manager == null) {
|
|
|
+ //开启监听
|
|
|
+ manager = ScreenShotListenManager.newInstance(getApplicationContext());
|
|
|
+ manager.setListener(
|
|
|
+ new ScreenShotListenManager.OnScreenShotListener() {
|
|
|
+ public void onShot(String imagePath) {
|
|
|
+ addPng(imagePath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ manager.startListen();
|
|
|
+ }
|
|
|
return super.onStartCommand(intent, flags, startId);
|
|
|
}
|
|
|
private ScreenShotListenManager manager;
|