app/build.gradle | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/AndroidManifest.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/aidl/com/anyun/exam/lib/IRemoteInterface.aidl | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/java/com/anyun/exam/lib/AYSdk.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/java/com/anyun/exam/lib/MyServiceConn.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
lib/src/main/java/com/anyun/exam/lib/RemoteService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
app/build.gradle
@@ -33,4 +33,5 @@ testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation project(path: ':lib') } lib/src/main/AndroidManifest.xml
@@ -1,2 +1,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.anyun.exam.lib" /> package="com.anyun.exam.lib" > <application> <service android:name=".RemoteService" android:process=":reomte" android:exported="true"/> </application> </manifest> lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl
New file @@ -0,0 +1,12 @@ // IListenerlInterface.aidl package com.anyun.exam.lib; // Declare any non-default types here with import statements interface IListenerInterface { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void onMessageArrived(String json); } lib/src/main/aidl/com/anyun/exam/lib/IRemoteInterface.aidl
New file @@ -0,0 +1,16 @@ // IRemoteInterface.aidl package com.anyun.exam.lib; import com.anyun.exam.lib.IListenerInterface; // Declare any non-default types here with import statements interface IRemoteInterface { /** * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ void registListener(IListenerInterface i); void unRegistListener(IListenerInterface i); void add(); } lib/src/main/java/com/anyun/exam/lib/AYSdk.java
@@ -1,6 +1,8 @@ package com.anyun.exam.lib; import android.content.Context; import android.content.Intent; import android.util.Log; /** * MyApplication2 @@ -9,8 +11,13 @@ * All Rights Saved! Chongqing AnYun Tech co. LTD */ class AYSdk { private static final String TAG = "AYSDK"; //安运驾考系统 sdk 单例模式 private volatile static AYSdk ourInstance = null; private Context mContext; private MyServiceConn conn; static AYSdk getInstance() { if (ourInstance == null){ @@ -23,6 +30,31 @@ return ourInstance; } /** * 初始化SDK * @param context */ public void init(Context context){ this.mContext = context; //bind service Intent intent = new Intent(mContext,RemoteService.class); conn = new MyServiceConn(); mContext.bindService(intent,conn,Context.BIND_AUTO_CREATE); } /** * 解绑 */ public void uninit(){ if (mContext != null){ mContext.unbindService(conn); }else{ Log.e(TAG,"mContext == null,please init SDK firstly"); throw new RuntimeException("mContext == null,please init SDK firstly"); } } private AYSdk() { } } lib/src/main/java/com/anyun/exam/lib/MyServiceConn.java
New file @@ -0,0 +1,33 @@ package com.anyun.exam.lib; import android.content.ComponentName; import android.content.ServiceConnection; import android.os.IBinder; /** * MyApplication2 * Created by lzw on 2019/6/5. 13:35:18 * 邮箱:632393724@qq.com * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class MyServiceConn implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { } @Override public void onBindingDied(ComponentName name) { } @Override public void onNullBinding(ComponentName name) { } } lib/src/main/java/com/anyun/exam/lib/RemoteService.java
@@ -3,7 +3,10 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.support.annotation.Nullable; import android.util.Log; /** * MyApplication2 @@ -12,9 +15,43 @@ * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class RemoteService extends Service { private static final String TAG = "RemoteService"; private RemoteCallbackList<IListenerInterface> mListenerList = new RemoteCallbackList(); private IRemoteInterface.Stub iRemoteInterface = new IRemoteInterface.Stub(){ @Override public void registListener(IListenerInterface i) throws RemoteException { //注册回调方法 mListenerList.register(i); } @Override public void unRegistListener(IListenerInterface i) throws RemoteException { mListenerList.unregister(i); } @Override public void add() throws RemoteException { } }; @Nullable @Override public IBinder onBind(Intent intent) { return null; return iRemoteInterface; } @Override public void onCreate() { super.onCreate(); Log.i(TAG,"onCreate()"); } @Override public void onDestroy() { super.onDestroy(); Log.i(TAG,"onDestroy"); } }