SDKService
public class SDKService extends Service {
private String TAG = "TEST";
@Override
public void onCreate() {
super.onCreate();
LogUtils.e(TAG,">>onCreate APK: ");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
LogUtils.e(TAG,">>onStartCommand");
return START_STICKY;
}
@Override
public void onDestroy() {
LogUtils.e(TAG,">>onDestroy");
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
LogUtils.e(TAG,">>onBind");
if (intent.getAction() == "com.suchao.demo.book"){
HttpRequestManager.getInstance(CPSDKService.this);
HttpRequestManager httpRequestManager = new HttpRequestManager(CPSDKService.this);
return mRATrafficVioclationBinder;
}else if(intent.getAction() == "com.suchao.demo.people"){
HttpRequestSemanticParseManager.getInstance(CPSDKService.this);
HttpRequestSemanticParseManager semanticParseManager = new HttpRequestSemanticParseManager(CPSDKService.this);
return mSemanticParseBinder;
}else {
return null;
}
}
private IBookSDKService.Stub mBookBinder = new IBookSDKService.Stub() {
@Override
public void requestAllProvinceList(int requestId, IRATrafficViolationSDKCallBack callBack) throws RemoteException {
HttpBookRequestManager.getInstance(SDKService.this).requestAllProvinceList(1, callBack);
}
};
private IPeopleSDKService.Stub mPeopleBinder = new IPeopleSDKService.Stub() {
@Override
public void voiceSemanticParse(String userId, String vin, String voiceContent, IVoiceContentCallBack callBack) throws RemoteException {
HttpPeopleRequestManager.getInstance(SDKService.this).voiceSemanticParse(userId, vin, voiceContent, callBack);
}
};
package com.reachauto.vspvehicle.ratrafficviolation;
import com.reachauto.vspvehicle.ratrafficviolation.IRATrafficViolationSDKCallBack;
interface IRATrafficVioclationSDKService {
void registerNTSC(IRATrafficViolationSDKCallBack callBack);
void requestAllProvinceList(int requestId, IRATrafficViolationSDKCallBack callBack);
void requestCityList(int requestId, String var1, IRATrafficViolationSDKCallBack callBack);
void requestViolationList(int requestId, String carInfoBeanJsonStr, IRATrafficViolationSDKCallBack callBack);
void queryDriversLicenceScore(int requestId, String licenseInfoBeanJsonStr, IRATrafficViolationSDKCallBack callBack);
}
package com.reachauto.vspvehicle.ratrafficviolation;
interface IRATrafficViolationSDKCallBack {
void ntscCallback(String code);
void responseProvince(String requestId, String errorCode, String jsonStr);
void responseCity(String requestId, String errorCode, String jsonStr);
void responseViolation(String requestId, String errorCode, String jsonStr);
void responseScoreInfo(String requestId, String errorCode, String jsonStr);
}
public class HttpRequestManager{
private Context context;
private static HttpRequestManager raTrafficViolationSDK;
private static final String app = "raTrafficViolation-Service";
public static HttpRequestManager getInstance(Context context){
if (raTrafficViolationSDK == null){
synchronized (HttpRequestManager.class){
if (raTrafficViolationSDK == null){
raTrafficViolationSDK = new HttpRequestManager(context);
}
}
}
return raTrafficViolationSDK;
}
public HttpRequestManager(Context context){
this.context = context;
}
public void requestAllProvinceList(final int requestId, final IRATrafficViolationSDKCallBack callBack){
Map map = new HashMap();
LogUtils.e(app + "RequestUtil>>>requestAllProvinceList");
String finalUrl = NetWorkUrlConstants.requestAllProvinceList_URL;
RequsestNet.basePOSTRequest(finalUrl, map, new IHttpCallback() {
@Override
public void onFailure(String errorCode, String errorMessage) {
try {
callBack.responseProvince(String.valueOf(requestId), errorCode, errorMessage);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onResponse(String data, String finalUrl) throws IOException {
try {
callBack.responseProvince(String.valueOf(requestId),"000000", data);
} catch (RemoteException e) {
e.printStackTrace();
}
}
});
}
}
public class RATrafficViolationSDK{
private Context context;
private RATrafficViolationSDKCallBack raTrafficViolationSDKCallBack;
private static RATrafficViolationSDK raTrafficViolationSDK;
private IRATrafficVioclationSDKService mService;
private static final String app = "raTrafficViolation_client";
private static String TAG = "NSR_VSP_CP";
private IRATrafficViolationSDKCallBackImpl mIRATrafficViolationSDKCallBackImpl;
private static RATrafficViolationSDK mInstance;
public static RATrafficViolationSDK getInstance(Context context, String vin){
if (mInstance == null){
synchronized (RATrafficViolationSDK.class){
if (mInstance == null){
mInstance = new RATrafficViolationSDK(context);
CommonConstants.VIN = vin;
}
}
}
return mInstance;
}
public RATrafficViolationSDK(Context context){
this.context = context;
}
private ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LogUtils.e(TAG, app + " >>> ServiceConnected Successful");
mService = IRATrafficVioclationSDKService.Stub.asInterface(service);
if (mService != null) {
LogUtils.e(TAG, app + "CPService服务链接成功");
} else {
LogUtils.e(TAG, app + " >>>>CPService服务链接失败 mService no connect");
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
LogUtils.e(TAG, app + "ServiceConnected Failed");
}
};
public void InitService(Context context){
Intent intent = new Intent();
intent.setAction(CommonConstants.AIDL_ACTION);
intent.setPackage(CommonConstants.AIDL_PACKAGE);
context.getApplicationContext().bindService(intent, mServiceConn, BIND_AUTO_CREATE);
LogUtils.e(TAG, app + " >>> 客户端 启动服务");
}
public void setRaTrafficViolationSDKCallBack(RATrafficViolationSDKCallBack raTrafficViolationSDKCallBack) {
this.raTrafficViolationSDKCallBack = raTrafficViolationSDKCallBack;
mIRATrafficViolationSDKCallBackImpl = new IRATrafficViolationSDKCallBackImpl();
LogUtils.e(TAG, app + "调用初始化服务方法");
InitService(context);
}
public void requestAllProvinceList(final int requestId) throws NullPointerException{
try {
if (mService == null){
LogUtils.e(TAG, app + "jar Request 接口》》》 mService = :" + mService);
throw new NullPointerException("CPService is not connect");
}
mService.requestAllProvinceList(requestId, mIRATrafficViolationSDKCallBackImpl);
} catch (RemoteException e) {
e.printStackTrace();
}
}
class IRATrafficViolationSDKCallBackImpl extends IRATrafficViolationSDKCallBack.Stub{
@Override
public void responseProvince(String requestId, String errorCode, String jsonStr) throws RemoteException {
RequestResult requestResult = new RequestResult();
if (errorCode.equals("000000")){
ProvinceListDO provinceListDO = new ProvinceListDO();
Gson gson = new Gson();
provinceListDO = gson.fromJson(jsonStr, ProvinceListDO.class);
ArrayList<ProvinceBean> provinceBeanArrayList = new ArrayList<ProvinceBean>();
if (provinceListDO.getResponseBody() != null){
for (ProvinceListDO.ResponseBodyBean bean:
provinceListDO.getResponseBody()) {
ProvinceBean provinceBean = new ProvinceBean();
provinceBean.setProvince_code(bean.getProvinceCode());
provinceBean.setProvince_abbr(bean.getProvinceAbbr());
provinceBean.setProvince(bean.getProvince());
provinceBeanArrayList.add(provinceBean);
}
requestResult.setResponseTime(String.valueOf(provinceListDO.getResponseTime()));
}
requestResult.setT(provinceBeanArrayList);
requestResult.setStatus("000000");
requestResult.setRequestId(String.valueOf(requestId));
raTrafficViolationSDKCallBack.responseProvince(requestResult);
}else {
requestResult.setStatus(errorCode);
requestResult.setMsg(jsonStr);
requestResult.setRequestId(String.valueOf(requestId));
raTrafficViolationSDKCallBack.responseProvince(requestResult);
}
}
}