Shanghai Sunmi Technology Co., Ltd. Sweeping Development
- 3 -
2. Connect Service(AIDL)
2.1. AIDL
AIDL is the abbreviation of Android Interface Definition language. It is a description
language of Android's internal process communication interface. Through it, we can define the
communication interface between processes.
2.2. Use AIDL
Establishing a connection can be divided into the following 5 steps:
1. Add the AIDL file included in the resource file to your project.
2. Implement ServiceConnection in the code class that controls scan code.
3. Call ApplicationContext.bindService() and pass it in the ServiceConnection
implementation. Note: bindservice is a non-blocking call, meaning that the call is not
completed immediately after the call is completed. ServiceConnected must prevail.
4. In the ServiceConnection.onServiceConnected() implementation, you receive an IBinder
instance (the invoked Service). Call IScanInterface.Stub.asInterface(service) to convert
the argument to IScanInterface type.
5. Now you can call the methods defined in the IScanInterface interface.
private static ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
scanInterface = IScanInterface.Stub.asInterface(service);
Log.i("setting", "Scanner Service Connected!");
}
@Override
public void onServiceDisconnected(ComponentName name) {
Log.e("setting", "Scanner Service Disconnected!");
scanInterface = null;
}
};
public void bindScannerService() {