ファイル名 | DchaLibrary |
ダウンロード | ダウンロード |
※Android Studioの場合です
app/libs配下に配置
app/build.gradleに以下を追加
dependencies { implementation files('libs/IDchaLibrary.jar') }
コードの例:
import jp.co.benesse.dcha.dchaservice.IDchaService; import jp.co.benesse.dcha.dchautilservice.IDchaUtilService; public class MainActivity extends Activity { private IDchaService mDchaService; private IDchaUtilService mIDchaUtilService; final string DCHA_SERVICE = "jp.co.benesse.dcha.dchaservice.DchaService"; final string PACKAGE_DCHASERVICE = "jp.co.benesse.dcha.dchaservice"; final string DCHA_UTIL_SERVICE = "jp.co.benesse.dcha.dchautilservice.DchaUtilService"; final string PACKAGE_DCHA_UTIL_SERVICE = "jp.co.benesse.dcha.dchautilservice"; public boolean bindDchaService(int flag, int dchaMode) { Intent intent = new Intent(); if (dchaMode == 1) { intent = new Intent(DCHA_SERVICE); intent.setPackage(PACKAGE_DCHASERVICE); } else if (dchaMode == 2) { intent = new Intent(DCHA_UTIL_SERVICE); intent.setPackage(PACKAGE_DCHA_UTIL_SERVICE); } return !bindService(intent, new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder iBinder) { if (dchaMode == 1) { mDchaService = IDchaService.Stub.asInterface(iBinder); try { /* 処理が複数ある場合ここでは変数flagの値でmDchaService,~の処理を決める */ mDchaService.~ } catch (RemoteException ignored) { } } else if (dchaMode == 2) { mIDchaUtilService = IDchaUtilService.Stub.asInterface(iBinder); try { /* 処理が複数ある場合ここでは変数flagの値でmDchaUtilService,~の処理を決める */ mIDchaUtilService.~ } catch (RemoteException ignored) { } } unbindService(this); } @Override public void onServiceDisconnected(ComponentName name) { unbindService(this); } }, Context.BIND_AUTO_CREATE); } }
Created by Kobold831