EasyManua.ls Logo

Sunmi L2 - Connecting Sunmi Scanner Service via AIDL; Understanding AIDL; Establishing AIDL Connection Steps

Sunmi L2
18 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Shanghai Sunmi Technology Co., Ltd. Sweeping Development
- 3 -
2. Connect ServiceAIDL
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.
Binding service example
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() {

Related product manuals