Preliminary understanding of android development -aidl

These days writing project uses Bluetooth connectivity small ticket printer, which has a knowledge point is to use the aidl, this thing is not clear how to use, what to do.

On Mu lesson learned about curriculum, probably understand some of it.

First aidl usage scenarios, multi-threaded, multi-client calls, IPC, the IPC is not sure what to do. Then think of this printer usage, fits scene multi-client calls.
It is my understanding, it may be more superficial.

aidl can be simply understood as two different processes need to interact, for example, want to use a number of functional interface multiplexing applications b, in order to save development time and improve development efficiency. But the application is not a direct call to b, and this is because there is such protection between applications to avoid some security issues.
Therefore, it uses AIDL, by application of a low-level calls application system b, b corresponding to the application should also be multiplexed to the application interface exposes a.
Here we use b as a server, the application as a client.

One thing to note, the server and the client package names need to be consistent.

AIDL Folder to create a folder, rather than ordinary directories.

After android studio created aidl client, you need to be recompiled, will generate an interface file for the call.

Return to call this a small ticket printer, import sdk printer technology provided by. Create a folder and create aidl aidl file.

package com.gprinter.aidl;
interface GpService{  
	int openPort(int PrinterId,int PortType,String DeviceName,int PortNumber);
	void closePort(int PrinterId);
	int getPrinterConnectStatus(int PrinterId);
	int printeTestPage(int PrinterId);   
  	void queryPrinterStatus(int PrinterId,int Timesout,int requestCode);
  	int getPrinterCommandType(int PrinterId);
	int sendEscCommand(int PrinterId, String b64);
  	int sendLabelCommand(int PrinterId, String  b64);
	void isUserExperience(boolean userExperience);
	String getClientID();
	int setServerIP(String ip, int port);
} 

aidl syntax is very familiar, similar to the common interface with us. Support for basic data types, excluding short. You can also customize the type. The above are some of the ways aidl document printer calls.

Specific calls and enable subsequent finishing do it.

Published 139 original articles · won praise 35 · views 180 000 +

Guess you like

Origin blog.csdn.net/kanglovejava/article/details/98315843