From db2651457acfd5bfb6e3031db3e6b89eafa57a47 Mon Sep 17 00:00:00 2001
From: endian11 <Dana_Lee1016@126.com>
Date: 星期三, 05 六月 2019 16:58:41 +0800
Subject: [PATCH] 调用远程服务接口成功; 以后远程服务需要增加功能(客户端app调用),直接在IAYExamInterface里添加,然后在RemoteService实现功能;在AYSDK中调用remoteservice实现的功能;增加SDK回调给客户端app的callback,IAYEXAMListener;增减binder断裂监听
---
lib/src/main/java/com/anyun/exam/lib/RemoteService.java | 42 +++++++++++++++++++++++++++++++++++++++++-
1 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
index 1982465..f525584 100644
--- a/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
+++ b/lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -8,6 +8,8 @@
import android.support.annotation.Nullable;
import android.util.Log;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
* MyApplication2
* Created by lzw on 2019/6/5. 13:22:46
@@ -17,7 +19,11 @@
public class RemoteService extends Service {
private static final String TAG = "RemoteService";
+ //鏈嶅姟鏄惁閿�姣�
+ private AtomicBoolean mIsServiceDestroyed = new AtomicBoolean(false);
private RemoteCallbackList<IListenerInterface> mListenerList = new RemoteCallbackList();
+ private IListenerInterface mListener;
+ private int msgId = 0;
private IRemoteInterface.Stub iRemoteInterface = new IRemoteInterface.Stub(){
@Override
public void registListener(IListenerInterface i) throws RemoteException {
@@ -32,7 +38,7 @@
@Override
public void add() throws RemoteException {
-
+ Log.i(TAG,"瀹㈡埛绔皟鐢ㄦ湇鍔$鏂规硶");
}
@@ -47,11 +53,45 @@
public void onCreate() {
super.onCreate();
Log.i(TAG,"onCreate()");
+ new Thread(new Worker()).start();
+ }
+
+ private class Worker implements Runnable{
+
+ @Override
+ public void run() {
+ while (!mIsServiceDestroyed.get()){
+ try {
+ Thread.sleep(4*1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ onMessageArrived(String.format("娑堟伅ID锛�%d,璇锋敞鎰忔煡鏀�",msgId++));
+ }
+
+ }
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i(TAG,"onDestroy");
+ mIsServiceDestroyed.set(true);
+ }
+
+ private void onMessageArrived(String json){
+ int N = mListenerList.getRegisteredCallbackCount();
+ for (int i = 0; i < N; i++) {
+ mListenerList.beginBroadcast();
+ mListener = mListenerList.getBroadcastItem(i);
+ if (mListener != null){
+ try {
+ mListener.onMessageArrived(json);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ mListenerList.finishBroadcast();
+ }
}
}
--
Gitblit v1.8.0