{"id":36453,"date":"2024-11-26T09:54:30","date_gmt":"2024-11-26T01:54:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36453\/"},"modified":"2024-11-26T09:54:30","modified_gmt":"2024-11-26T01:54:30","slug":"android-%e4%b8%b2%e5%8f%a3%e9%80%9a%e4%bf%a1%e6%8e%a5%e6%94%b6%e6%95%b0%e6%8d%ae%e5%a4%b1%e8%b4%a5%ef%bc%9a%e4%b8%ba%e4%bb%80%e4%b9%88-ondatareceive-%e6%9c%89%e6%97%b6%e6%94%b6%e4%b8%8d%e5%88%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36453\/","title":{"rendered":"Android \u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 onDataReceive() \u6709\u65f6\u6536\u4e0d\u5230\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173115848571768.jpg\" class=\"aligncenter\" title=\"Android \u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 onDataReceive() \u6709\u65f6\u6536\u4e0d\u5230\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"Android \u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u5931\u8d25\uff1a\u4e3a\u4ec0\u4e48 onDataReceive() \u6709\u65f6\u6536\u4e0d\u5230\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u7684\u7591\u8651<\/strong><\/p>\n<p>\u5728 android \u5f00\u53d1\u4e2d\uff0c\u60a8\u4f7f\u7528 ondatareceive() \u51fd\u6570\u6765\u63a5\u6536\u4e32\u53e3\u6570\u636e\u3002\u7136\u800c\uff0c\u5728\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\u65f6\uff0c\u60a8\u4f1a\u53d1\u73b0\u6709\u65f6\u65e0\u6cd5\u6536\u5230\u6570\u636e\uff1a<\/p>\n<pre>serialengine.sendmessage(sendcommand.sendo2zero(), \"s4\");\nif (mainactivity.setgaszero3 == null) {\n    xtoastutils.toast(\"\u8bfb\u53d6\u5931\u8d25\uff01\");\n    mainactivity.issend3 = true;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u95ee\u9898\u5206\u6790<\/strong><\/p>\n<p>\u6839\u636e\u60a8\u7684\u63cf\u8ff0\uff0c\u5728\u53d1\u9001\u547d\u4ee4\u540e\uff0c\u6709\u65f6 ondatareceive() \u51fd\u6570\u65e0\u6cd5\u63a5\u6536\u5230\u4efb\u4f55\u6570\u636e\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li> <strong>\u5f02\u6b65\u901a\u4fe1\uff1a<\/strong>\u4e32\u53e3\u901a\u4fe1\u662f\u5f02\u6b65\u7684\uff0c\u8fd9\u610f\u5473\u7740\u53d1\u9001\u547d\u4ee4\u548c\u63a5\u6536\u6570\u636e\u4e0d\u4e00\u5b9a\u53d1\u751f\u5728\u540c\u4e00\u65f6\u95f4\u3002<\/li>\n<li> <strong>\u7f13\u51b2\u533a\u5ef6\u8fdf\uff1a<\/strong>\u6570\u636e\u53ef\u80fd\u5728\u7f13\u51b2\u533a\u4e2d\u505c\u7559\u4e00\u6bb5\u65f6\u95f4\uff0c\u7136\u540e\u518d\u7531 android \u7cfb\u7edf\u901a\u77e5\u5230 ondatareceive() \u51fd\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u4e00\u4e2a\u7b80\u5355\u65b9\u6cd5\u662f\u5728 ondatareceive() \u51fd\u6570\u4e2d\u6dfb\u52a0\u5ef6\u65f6\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>@Override\npublic void onDataReceive(byte[] bytes, int i) {\n    if (bytes != null &amp;&amp; bytes.length != 0) {\n        if (bytes[0] == 1 &amp;&amp; bytes[1] == 3) {\n            MainActivity.setGaszero = bytes;\n        }\n    }\n\n    \/\/ \u6dfb\u52a0\u5ef6\u65f6\n    try {\n        Thread.sleep(100);\n    } catch (InterruptedException e) {\n        e.printStackTrace();\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u5ef6\u65f6\u53ef\u4ee5\u8ba9\u7f13\u51b2\u533a\u6709\u8db3\u591f\u7684\u65f6\u95f4\u63a5\u6536\u5b8c\u5168\u90e8\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fAndroid \u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u5931\u8d25\uff1a onDataReceive() \u6709\u65f6\u6536\u4e0d\u5230\u6570\u636e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e32\u53e3\u901a\u4fe1\u63a5\u6536\u6570\u636e\u7684\u7591\u8651 \u5728 android \u5f00\u53d1\u4e2d\uff0c\u60a8\u4f7f\u7528 ondatareceive() \u51fd\u6570\u6765\u63a5\u6536\u4e32\u53e3\u6570\u636e\u3002\u7136\u800c\uff0c\u5728\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801\u65f6\uff0c\u60a8\u4f1a\u53d1\u73b0\u6709\u65f6\u65e0\u6cd5\u6536\u5230\u6570\u636e\uff1a serialengine.sendmessage(sendcommand.sendo2zero(), &#8220;s4&#8221;); if (mainactivity.setgaszero3 == null) { xtoastutils.toast(&#8220;\u8bfb\u53d6\u5931\u8d25\uff01&#8221;); mainactivity.issend3 = true; } \u767b\u5f55\u540e\u590d\u5236 \u95ee\u9898\u5206\u6790 \u6839\u636e\u60a8\u7684\u63cf\u8ff0\uff0c\u5728\u53d1\u9001\u547d\u4ee4\u540e\uff0c\u6709\u65f6 ondatareceive() \u51fd\u6570\u65e0\u6cd5\u63a5\u6536\u5230\u4efb\u4f55\u6570\u636e\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a \u5f02\u6b65\u901a\u4fe1\uff1a\u4e32\u53e3\u901a\u4fe1\u662f\u5f02\u6b65\u7684\uff0c\u8fd9\u610f\u5473\u7740\u53d1\u9001\u547d\u4ee4\u548c\u63a5\u6536\u6570\u636e\u4e0d\u4e00\u5b9a\u53d1\u751f\u5728\u540c\u4e00\u65f6\u95f4\u3002 \u7f13\u51b2\u533a\u5ef6\u8fdf\uff1a\u6570\u636e\u53ef\u80fd\u5728\u7f13\u51b2\u533a\u4e2d\u505c\u7559\u4e00\u6bb5\u65f6\u95f4\uff0c\u7136\u540e\u518d\u7531 android \u7cfb\u7edf\u901a\u77e5\u5230 ondatareceive() \u51fd\u6570\u3002 \u89e3\u51b3\u65b9\u6848 \u89e3\u51b3\u6b64\u95ee\u9898\u7684\u4e00\u4e2a\u7b80\u5355\u65b9\u6cd5\u662f\u5728 ondatareceive() \u51fd\u6570\u4e2d\u6dfb\u52a0\u5ef6\u65f6\u3002\u4f8b\u5982\uff1a @Override public void onDataReceive(byte[] bytes, int i) { if (bytes != null &amp;&amp; bytes.length != 0) { if (bytes[0] == 1 &amp;&amp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-36453","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36453","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=36453"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36453\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36453"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36453"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36453"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}