l***@163.com
l***@163.com
  • 发布:2020-10-14 17:03
  • 更新:2024-06-26 11:03
  • 阅读:1566

请问uniapp 该如何实现AIDL呢?有没有相关范例参考下

分类:uni-app

如题:有个安卓平板,带传感接口的,接入了称重传感器,(由于不是用com口传输数据,无法使用插件市场的com数据传输范例处理),根据厂家的sdk,他们使用AIDL进行数据交互,请问uniapp 该如何实现AIDL呢?有没有相关范例参考下! 附件为厂家的sdk,带app! 谢谢

2020-10-14 17:03 负责人:无 分享
已邀请:
coder_888

coder_888

兄弟解决了没,我也遇到同样的问题。1726023036麻烦加我qq
有偿咨询。

9***@qq.com

9***@qq.com - along

解决了吗

w***@163.com

w***@163.com

public class scaleModule extends UniModule {
private static final String PACKAGE_NAME = "com.tbossgroup.tbscale.aidl";
private static final String ACTION = "com.tbossgroup.tbscale.OTScaleService";
private String errMsg = "";
private float zhongliang = 0;
private TBScaleAidlInterface mTBScaleAidlInterface;
private ServiceConnection mServiceConnectionn = new ServiceConnection() {

    //绑定服务,回调onBind()方法  
    @Override  
    public void onServiceConnected(ComponentName name, IBinder service) {  
        mTBScaleAidlInterface = TBScaleAidlInterface.Stub.asInterface(service);  
    }  

    @Override  
    public void onServiceDisconnected(ComponentName name) {  
        mTBScaleAidlInterface = null;  
    }  
};  
public void ChatModule(){  
    //绑定服务端的serviceu  
    Intent intent = new Intent();  
    intent.setAction(ACTION);  
    intent.setPackage(PACKAGE_NAME);  
    mUniSDKInstance.getContext().bindService(intent, mServiceConnectionn, Context.BIND_AUTO_CREATE);  
}  
public void refreshWeightRecord() {  
    try {  
        //获取净重  
        zhongliang = mTBScaleAidlInterface.getNetWeight();  
    } catch (Exception e) {  
        //e.printStackTrace();  
       errMsg = e.toString();  
    }  
}  
@UniJSMethod(uiThread = false)  
public void showScale(JSONObject options, UniJSCallback callback) {  

    if(callback != null){  
         ChatModule();  
        refreshWeightRecord();  
        JSONObject data = new JSONObject();  
        data.put("value",zhongliang);  
        data.put("errMsg",errMsg);  
        callback.invoke(data);  
    }  
}  

}
这是我调通的代码

要回复问题请先登录注册