当前位置: 首页 > news >正文

海南网站建设软件cms源码下载

海南网站建设软件,cms源码下载,网站没有备案用什么cdn,wordpress新版本编辑器制作控制蓝牙小车app 想制作一个蓝牙小车#xff0c;通过手机app程序操控小车运行#xff0c;制作分2个部分#xff08;app制作#xff0c;蓝牙小车硬件以及程序制作#xff09;#xff0c;先完成第一个部分app制作#xff0c;本次app是通过androidstudio软件来制作安卓…制作控制蓝牙小车app 想制作一个蓝牙小车通过手机app程序操控小车运行制作分2个部分app制作蓝牙小车硬件以及程序制作先完成第一个部分app制作本次app是通过androidstudio软件来制作安卓应用程序 一、添加权限 在AndroidManifest.xml文件中添加权限 !-- 蓝牙操作权限 --uses-permission android:nameandroid.permission.BLUETOOTH/!-- 蓝牙配对权限--uses-permission android:nameandroid.permission.BLUETOOTH_ADMIN/!--仅在支持BLE蓝牙4.0及以上的设备上运行--uses-feature android:nameandroid.hardware.bluetooth_le android:requiredtrue/!--如果Android6.0蓝牙搜索不到设备需要补充以下两个权限--uses-permission android:nameandroid.permission.ACCESS_FINE_LOCATION/uses-permission android:nameandroid.permission.ACCESS_COARSE_LOCATION/uses-permission android:nameandroid.permission.BLUETOOTH_CONNECT /二、设计界面 这里需要新建一个连接蓝牙的界面以及活动这里新建的连接蓝牙活动取名Bluetooth_set 主界面 连接蓝牙界面 界面设计比较简单无非就是布局和控件id设置 三、功能实现 MainActivity.java文件代码 package com.example.myapplication_ble_hc7;import androidx.appcompat.app.AppCompatActivity;import android.bluetooth.BluetoothAdapter; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast;import java.io.IOException;import static com.example.myapplication_ble_hc7.Bluetooth_set.bluetoothSocket;public class MainActivity extends AppCompatActivity {Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button_set findViewById(R.id.button_set);button_set.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {Intent intent new Intent(MainActivity.this, Bluetooth_set.class);startActivity(intent);//跳转到设置界面}});final Button button_go findViewById(R.id.button_go);button_go.setBackgroundColor(Color.GREEN);final Button button_left findViewById(R.id.button_left);button_left.setBackgroundColor(Color.GREEN);final Button button_right findViewById(R.id.button_right);button_right.setBackgroundColor(Color.GREEN);final Button button_stop findViewById(R.id.button_back);button_stop.setBackgroundColor(Color.GREEN);TextView textView findViewById(R.id.textView2);if(bluetoothSocketnull){textView.setText(蓝牙未经连接);textView.setBackgroundColor(Color.RED);}else {textView.setText(蓝牙已经连接);textView.setBackgroundColor(Color.BLUE);}button_go.setOnTouchListener(new View.OnTouchListener() {Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {switch (motionEvent.getAction()){case MotionEvent.ACTION_DOWN:send(1);button_go.setBackgroundColor(Color.RED);break;case MotionEvent.ACTION_UP:send(0);button_go.setBackgroundColor(Color.GREEN);break;}return true;}});button_left.setOnTouchListener(new View.OnTouchListener() {Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {switch (motionEvent.getAction()){case MotionEvent.ACTION_DOWN:send(2);button_left.setBackgroundColor(Color.RED);break;case MotionEvent.ACTION_UP:send(0);button_left.setBackgroundColor(Color.GREEN);break;}return true;}});button_right.setOnTouchListener(new View.OnTouchListener() {Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {switch (motionEvent.getAction()){case MotionEvent.ACTION_DOWN:send(3);button_right.setBackgroundColor(Color.RED);break;case MotionEvent.ACTION_UP:send(0);button_right.setBackgroundColor(Color.GREEN);break;}return true;}});button_stop.setOnTouchListener(new View.OnTouchListener() {Overridepublic boolean onTouch(View view, MotionEvent motionEvent) {switch (motionEvent.getAction()){case MotionEvent.ACTION_DOWN:send(4);button_stop.setBackgroundColor(Color.RED);break;case MotionEvent.ACTION_UP:send(0);button_stop.setBackgroundColor(Color.GREEN);break;}return true;}});}public void send(int intData){if(bluetoothSocketnull) {//先判断是否连接Toast.makeText(MainActivity.this,设备未连接,Toast.LENGTH_SHORT).show();}else {try {bluetoothSocket.getOutputStream().write(intData);//建立数据库} catch (IOException e) { }}} }在Bluetooth_set.java文件中代码 package com.example.myapplication_ble_hc7;import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat;import android.annotation.SuppressLint; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.Toast;import java.io.IOException; import java.util.ArrayList; import java.util.Set; import java.util.UUID;public class Bluetooth_set extends AppCompatActivity {public static BluetoothSocket bluetoothSocket;UUID MY_UUIDUUID.fromString(00001101-0000-1000-8000-00805f9b34fb);//符合uuid格式就行ArrayListString ble_list new ArrayList();//创建数组列表ArrayListBluetoothDevice blenew ArrayList();//用来存放蓝牙设备SuppressLint(MissingPermission)Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_bluetooth_set);Button button_back findViewById(R.id.button_back);ListView listView findViewById(R.id.ble_list);button_back.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {Intent intent new Intent(Bluetooth_set.this, MainActivity.class);startActivity(intent);//返回到主界面}});BluetoothAdapter bluetoothAdapter BluetoothAdapter.getDefaultAdapter();//获取设备if (bluetoothAdapter null) {//判断设备是否支持蓝牙Toast.makeText(Bluetooth_set.this, 注意设备不支持蓝牙, Toast.LENGTH_SHORT).show();} else {Toast.makeText(Bluetooth_set.this, 设备支持蓝牙, Toast.LENGTH_SHORT).show();}if (!bluetoothAdapter.isEnabled()) { //判断设备是否打开蓝牙// bluetoothAdapter.enable();//打开蓝牙Intent enableBtIntent new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);startActivityForResult(enableBtIntent,1); //通过意图打开蓝牙}SetBluetoothDevice device bluetoothAdapter.getBondedDevices();//获取已经配对的设备并存放到列表if(device.size()0){for(BluetoothDevice mdevice:device){ble.add(mdevice);//添加蓝牙ble_list.add(mdevice.getName());//将获取的蓝牙名称添加到列表}}ArrayAdapterString view_listnew ArrayAdapter(this,android.R.layout.simple_list_item_1,ble_list);//创建列表显示的适配器listView.setAdapter(view_list);//显示在列表里面listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {Overridepublic void onItemClick(AdapterView? adapterView, View view, int i, long l) {// BluetoothDevice bluetoothDevice ble.get(i);//获取需要单击的蓝牙try {bluetoothSocketble.get(i).createInsecureRfcommSocketToServiceRecord(MY_UUID);//获取需要单击的蓝牙,并且连接填入UUIDbluetoothSocket.connect();//蓝牙连接} catch (IOException e) {}Toast.makeText(Bluetooth_set.this, 蓝牙ble.get(i).getName()已经连接, Toast.LENGTH_SHORT).show();}});} }四、效果呈现 把蓝牙先连接到电脑 安卓设备连接蓝牙并发送数据下面是接收数据情况我这边分别使用0,1,2,3,4表示停、前进、左转、右转、后退 第一阶段app程序暂时通过验证接下来制作蓝牙小车
http://www.zqtcl.cn/news/554350/

相关文章:

  • 国外被动收入网站做的好的成都网站建设 川icp备
  • 网站的微信推广怎么做php在电子商务网站建设中的应用研究 戴书浩
  • 中山做网站有什么做logo网站
  • 建设网站要什么手续义乌简游网络科技有限公司
  • 深圳做企业网站的音乐网站设计
  • 互联网网站如何做菜鸟教程自学网
  • 网站模板上传工具网站报名照片怎么做
  • 做网站如何备案东城做企业网站多少钱
  • 建设手机网站的目的广告制作行业发展前景
  • 手工艺品网站建设目的长春有哪些网络设计公司
  • 重庆建设工程招标网站淮南58同城网
  • 有域名在本机上做网站psd素材
  • 做拍拍拍拍网站网站宣传的劣势
  • 建设银行官方网站诚聘英才亚马逊店铺出售网站
  • 佛山房地产网站建设万网域名查询接口
  • 新建的网站必须要备案吗优购物网
  • 陕西省住房和城乡建设厅官方网站智能网站建设制作
  • 英语故事网站建设镇江大港信息港
  • 接单做一个网站多少钱商河网站建设
  • 网站建设s南昌网站建设服务
  • 免费的素材网站有哪些重庆网页设计公司排名
  • 内网网站建设汇报即商通网站建设推广
  • 企业建站系统是什么学校的网站怎么做的
  • 哪个大学的网站做的最好看网页制作教材素材
  • 南里商濮阳网站建设福田附件网站建设公司
  • 监控性能网站模板网页设计公司找哪家
  • 校园网站建设教程安卓小程序开发入门
  • 找人做网站需要注意什么seo工作
  • 做外贸有哪些好的网站有哪些内容响应式网站wordpress摄影
  • iis 7.0 搭建网站做门户网站公司