日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WIFI小车APP

發(fā)布時間:2023/12/10 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WIFI小车APP 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

對應(yīng)這篇文章:433M射頻遙控?zé)簟⒄饎痈袘?yīng)燈、WIFI避障小車

目錄

  • 代碼概要
  • activity_contrl.xml
  • ContrlActivity.java
  • NetUtils.java
  • 詳細(xì)工程代碼下載

代碼概要

activity_contrl.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/test"tools:context=".ContrlActivity" ><LinearLayoutandroid:layout_centerVertical="true"android:layout_alignParentRight="true"android:layout_marginRight="100dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="vertical" ><Buttonandroid:id="@+id/btnqian"android:layout_width="100dp"android:layout_height="100dp"android:layout_weight="1"android:background="@drawable/btn_back"android:text="前進(jìn)"android:layout_margin="10dp"android:textColor="#ffffff" /><Buttonandroid:id="@+id/btnhou"android:layout_width="100dp"android:layout_height="100dp"android:layout_weight="1"android:layout_margin="10dp"android:background="@drawable/btn_back"android:text="后退"android:textColor="#ffffff" /></LinearLayout><LinearLayoutandroid:layout_centerVertical="true"android:layout_marginLeft="100dp"android:layout_height="wrap_content"android:layout_width="wrap_content"android:orientation="horizontal" ><Buttonandroid:id="@+id/btnzuo"android:layout_height="100dp"android:layout_width="100dp"android:layout_weight="1"android:background="@drawable/btn_back"android:text="左轉(zhuǎn)"android:layout_margin="10dp"android:textColor="#ffffff" /><Buttonandroid:id="@+id/btnyou"android:layout_height="100dp"android:layout_width="100dp"android:layout_weight="1"android:layout_margin="10dp"android:background="@drawable/btn_back"android:text="右轉(zhuǎn)"android:textColor="#ffffff" /></LinearLayout></RelativeLayout>

ContrlActivity.java

package com.gec.bluetoothcarlink;import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button;public class ContrlActivity extends Activity {Button qian;Button hou;Button zuo;Button you;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);// 璁劇疆鏃犳爣棰樻爮requestWindowFeature(Window.FEATURE_NO_TITLE);// 璁劇疆鍏ㄥ睆getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);// 淇濇寔灞忓箷甯鎬寒getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);setContentView(R.layout.activity_contrl);initView();}void initView() {qian = (Button) findViewById(R.id.btnqian);hou = (Button) findViewById(R.id.btnhou);zuo = (Button) findViewById(R.id.btnzuo);you = (Button) findViewById(R.id.btnyou);qian.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View arg0, MotionEvent event) {// TODO Auto-generated method stubswitch (event.getAction()) {case MotionEvent.ACTION_DOWN:new NetUtils("4").sendMessage();break;case MotionEvent.ACTION_UP: {new NetUtils("s").sendMessage();break;}}return false;}});hou.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View arg0, MotionEvent event) {// TODO Auto-generated method stubswitch (event.getAction()) {case MotionEvent.ACTION_DOWN:new NetUtils("5").sendMessage();break;case MotionEvent.ACTION_UP: {new NetUtils("s").sendMessage();break;}}return false;}});zuo.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View arg0, MotionEvent event) {// TODO Auto-generated method stubswitch (event.getAction()) {case MotionEvent.ACTION_DOWN:new NetUtils("6").sendMessage();break;case MotionEvent.ACTION_UP: {new NetUtils("z").sendMessage();break;}}return false;}});you.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View arg0, MotionEvent event) {// TODO Auto-generated method stubswitch (event.getAction()) {case MotionEvent.ACTION_DOWN:new NetUtils("7").sendMessage();break;case MotionEvent.ACTION_UP: {new NetUtils("z").sendMessage();break;}}return false;}});}}

NetUtils.java

package com.gec.bluetoothcarlink;import java.io.OutputStream; import java.net.Socket;import android.os.Handler;public class NetUtils {public String message;public String reTurnMes;public Handler handler;public NetUtils(String message) {this.message = message;}public NetUtils(String message, Handler handler) {this.message = message;this.handler = handler;}public void sendMessage() {new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubtry {Socket client = new Socket("192.168.1.217", 8888);//Socket client = new Socket(StartActivity.IP, Integer.parseInt(StartActivity.Port));OutputStream out = client.getOutputStream();out.write(message.getBytes());out.close();client.close();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}).start();} }

詳細(xì)工程代碼下載

https://download.csdn.net/download/zhuguanlin121/21023813?spm=1001.2014.3001.5501

總結(jié)

以上是生活随笔為你收集整理的WIFI小车APP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。