Commit f101361b by System Administrator

增加轮询方法

parent 1e5ccf2d
...@@ -51,11 +51,13 @@ public class ONService extends CordovaPlugin { ...@@ -51,11 +51,13 @@ public class ONService extends CordovaPlugin {
this.coolMethod(message, callbackContext); this.coolMethod(message, callbackContext);
return true; return true;
} }
if (action.endsWith("getMessage")) { if (action.endsWith("getMessage")) {
callbackContext.success(NotificationService.getOfflineAll()); callbackContext.success(NotificationService.getOfflineAll());
NotificationService.cleanOfflineBean(); NotificationService.cleanOfflineBean();
return true; return true;
} }
// 开启并绑定服务并5秒间隔调取getHistory() // 开启并绑定服务并5秒间隔调取getHistory()
if (action.equals("bindService")) { if (action.equals("bindService")) {
Intent intent = new Intent(cordova.getActivity(), NotificationService.class); Intent intent = new Intent(cordova.getActivity(), NotificationService.class);
...@@ -72,6 +74,8 @@ public class ONService extends CordovaPlugin { ...@@ -72,6 +74,8 @@ public class ONService extends CordovaPlugin {
connection, connection,
Service.BIND_AUTO_CREATE Service.BIND_AUTO_CREATE
); );
callbackContext.success("服务开启成功");
return true;
} }
// 开始间隔调取getHistory() // 开始间隔调取getHistory()
......
...@@ -115,7 +115,7 @@ public class NotificationService extends Service { ...@@ -115,7 +115,7 @@ public class NotificationService extends Service {
public MyBinder binder = new MyBinder(); public MyBinder binder = new MyBinder();
public static BeanOffline offlineAll = new BeanOffline();; // 给前端返回的离线数据 public static BeanOffline offlineAll = new BeanOffline(); // 给前端返回的离线数据
public static String getOfflineAll() { public static String getOfflineAll() {
String res = new Gson().toJson(offlineAll); String res = new Gson().toJson(offlineAll);
...@@ -357,8 +357,9 @@ public class NotificationService extends Service { ...@@ -357,8 +357,9 @@ public class NotificationService extends Service {
public boolean onUnbind(Intent intent) { public boolean onUnbind(Intent intent) {
Log.e(TAG, "onUnbind "); Log.e(TAG, "onUnbind ");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
stopForeground(STOP_FOREGROUND_REMOVE); // stopForeground(STOP_FOREGROUND_REMOVE);
} }
stopSelf();
return super.onUnbind(intent); return super.onUnbind(intent);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment