Hbuilder怎样才能实现AIDL接口 定义,或者需要安装什么样的插件?哪位大神有了解
- 发布:2018-09-07 22:55
- 更新:2020-10-14 20:32
- 阅读:2487
可以,
uniapp端
let Xia = plus.android.importClass('com.smartdevice.Printer')
let main = plus.android.runtimeMainActivity()
let xia = new Xia()
xia.init(main)
xia.test()
java端
public class Printer {
private static IZKCService mIzkcService;
// private static Printer instance = new Printer();
private ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
Log.e("client", "onServiceDisconnected");
mIzkcService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.e("client", "onServiceConnected+");
/**
服务绑定成功,获取到该服务接口对象,可通过该接口调用相关的接口方法来完成相应的功能
*success to get the sevice interface object
*/
mIzkcService = IZKCService.Stub.asInterface(service);
}
};
public void init(Activity app) {
Intent intent = new Intent("com.zkc.aidl.all");
// intent.setAction("com.zkc.aidl.all");
intent.setPackage("com.smartdevice.aidl");
// intent.setClassName("com.smartdevice.aidl.all","com.smartdevice.aidl.IZKCService");
app.startService(intent);
app.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
}
public void close(Activity app) {
app.unbindService(mServiceConn);
}
public void test() {
try {
mIzkcService.printerInit();
mIzkcService.checkPrinterAvailable();
mIzkcService.printGBKText("dddddddddddddddddddddddddddddddd");
mIzkcService.printGBKText("dddddddddddddddddddddddddddddddd");
mIzkcService.printGBKText("dddddddddddddddddddddddddddddddd");
mIzkcService.printGBKText("dddddddddddddddddddddddddddddddd");
} catch (RemoteException e) {
Log.e("client", "onServiceConnected+eeee");
e.printStackTrace();
}
}
}
周BUG
uniapp端有么有比较完整使用AIDL案例
2019-08-16 21:55