高端网站设计定制公司福州公司做网站

news/2025/9/23 11:38:53/文章来源:
高端网站设计定制公司,福州公司做网站,建设银行深圳天健世纪支行网站,成都旅游的网站建设1.启动App后: 判断-蓝牙是否打开#xff08;所有功能必须在打牙打开的情况下才能用) 已打开: 启动代码中的蓝牙通讯Service 未打开: 发布 打开蓝牙意图(系统)#xff0c;根据Activity返回进场操作 打开成功,启动代码中的蓝牙通讯Service 用户点back或失败 退出App 2.蓝牙…  1.启动App后: 判断-蓝牙是否打开所有功能必须在打牙打开的情况下才能用) 已打开: 启动代码中的蓝牙通讯Service 未打开: 发布 打开蓝牙意图(系统)根据Activity返回进场操作           打开成功,启动代码中的蓝牙通讯Service           用户点back或失败 退出App   2.蓝牙设备列表: 2.1显示已经配对列表: 注册蓝牙设备发现广播    广播中将发现的设备添加到列表2.2当用户点Scan时启动蓝牙发现发现设备时会收到广播事件。 2.3用户点某个条目时将改条目的 MAC返回给主Activity(调用了startActivityForResult的Activity)   3.使设备可发现 private void ensureDiscoverable() {Log.d(TAG, ensure discoverable);if (mBluetoothAdapter.getScanMode() !BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {Intent discoverableIntent new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);startActivity(discoverableIntent);}} View Code  4.蓝牙socket操作 /** Copyright (C) 2009 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the License);* you may not use this file except in compliance with the License.* You may obtain a copy of the License at** http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an AS IS BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.example.android.BluetoothChat;import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.UUID;import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Context; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log;/*** This class does all the work for setting up and managing Bluetooth* connections with other devices. It has a thread that listens for* incoming connections, a thread for connecting with a device, and a* thread for performing data transmissions when connected.*/ public class BluetoothChatService {// Debuggingprivate static final String TAG BluetoothChatService;private static final boolean D true;// Name for the SDP record when creating server socketprivate static final String NAME_SECURE BluetoothChatSecure;private static final String NAME_INSECURE BluetoothChatInsecure;// Unique UUID for this applicationprivate static final UUID MY_UUID_SECURE UUID.fromString(00001101-0000-1000-8000-00805F9B34FB);//UUID.fromString(fa87c0d0-afac-11de-8a39-0800200c9a66);private static final UUID MY_UUID_INSECURE UUID.fromString(8ce255c0-200a-11e0-ac64-0800200c9a66);// Member fieldsprivate final BluetoothAdapter mAdapter;private final Handler mHandler;private AcceptThread mSecureAcceptThread;private AcceptThread mInsecureAcceptThread;private ConnectThread mConnectThread;private ConnectedThread mConnectedThread;private int mState;// Constants that indicate the current connection statepublic static final int STATE_NONE 0; // were doing nothingpublic static final int STATE_LISTEN 1; // now listening for incoming connectionspublic static final int STATE_CONNECTING 2; // now initiating an outgoing connectionpublic static final int STATE_CONNECTED 3; // now connected to a remote device/*** Constructor. Prepares a new BluetoothChat session.* param context The UI Activity Context* param handler A Handler to send messages back to the UI Activity*/public BluetoothChatService(Context context, Handler handler) {mAdapter BluetoothAdapter.getDefaultAdapter();mState STATE_NONE;mHandler handler;}/*** Set the current state of the chat connection* param state An integer defining the current connection state*/private synchronized void setState(int state) {if (D) Log.d(TAG, setState() mState - state);mState state;// Give the new state to the Handler so the UI Activity can updatemHandler.obtainMessage(BluetoothChat.MESSAGE_STATE_CHANGE, state, -1).sendToTarget();}/*** Return the current connection state. */public synchronized int getState() {return mState;}/*** Start the chat service. Specifically start AcceptThread to begin a* session in listening (server) mode. Called by the Activity onResume() */public synchronized void start() {if (D) Log.d(TAG, start);// Cancel any thread attempting to make a connectionif (mConnectThread ! null) {mConnectThread.cancel(); mConnectThread null;}// Cancel any thread currently running a connectionif (mConnectedThread ! null) {mConnectedThread.cancel(); mConnectedThread null;}setState(STATE_LISTEN);// Start the thread to listen on a BluetoothServerSocketif (mSecureAcceptThread null) {mSecureAcceptThread new AcceptThread(true);mSecureAcceptThread.start();}if (mInsecureAcceptThread null) {mInsecureAcceptThread new AcceptThread(false);mInsecureAcceptThread.start();}}/*** Start the ConnectThread to initiate a connection to a remote device.* param device The BluetoothDevice to connect* param secure Socket Security type - Secure (true) , Insecure (false)*/public synchronized void connect(BluetoothDevice device, boolean secure) {if (D) Log.d(TAG, connect to: device);// Cancel any thread attempting to make a connectionif (mState STATE_CONNECTING) {if (mConnectThread ! null) {mConnectThread.cancel(); mConnectThread null;}}// Cancel any thread currently running a connectionif (mConnectedThread ! null) {mConnectedThread.cancel(); mConnectedThread null;}// Start the thread to connect with the given devicemConnectThread new ConnectThread(device, secure);mConnectThread.start();setState(STATE_CONNECTING);}/*** Start the ConnectedThread to begin managing a Bluetooth connection* param socket The BluetoothSocket on which the connection was made* param device The BluetoothDevice that has been connected*/public synchronized void connected(BluetoothSocket socket, BluetoothDevicedevice, final String socketType) {if (D) Log.d(TAG, connected, Socket Type: socketType);// Cancel the thread that completed the connectionif (mConnectThread ! null) {mConnectThread.cancel(); mConnectThread null;}// Cancel any thread currently running a connectionif (mConnectedThread ! null) {mConnectedThread.cancel(); mConnectedThread null;}// Cancel the accept thread because we only want to connect to one deviceif (mSecureAcceptThread ! null) {mSecureAcceptThread.cancel();mSecureAcceptThread null;}if (mInsecureAcceptThread ! null) {mInsecureAcceptThread.cancel();mInsecureAcceptThread null;}// Start the thread to manage the connection and perform transmissionsmConnectedThread new ConnectedThread(socket, socketType);mConnectedThread.start();// Send the name of the connected device back to the UI ActivityMessage msg mHandler.obtainMessage(BluetoothChat.MESSAGE_DEVICE_NAME);Bundle bundle new Bundle();bundle.putString(BluetoothChat.DEVICE_NAME, device.getName());msg.setData(bundle);mHandler.sendMessage(msg);setState(STATE_CONNECTED);}/*** Stop all threads*/public synchronized void stop() {if (D) Log.d(TAG, stop);if (mConnectThread ! null) {mConnectThread.cancel();mConnectThread null;}if (mConnectedThread ! null) {mConnectedThread.cancel();mConnectedThread null;}if (mSecureAcceptThread ! null) {mSecureAcceptThread.cancel();mSecureAcceptThread null;}if (mInsecureAcceptThread ! null) {mInsecureAcceptThread.cancel();mInsecureAcceptThread null;}setState(STATE_NONE);}/*** Write to the ConnectedThread in an unsynchronized manner* param out The bytes to write* see ConnectedThread#write(byte[])*/public void write(byte[] out) {// Create temporary objectConnectedThread r;// Synchronize a copy of the ConnectedThreadsynchronized (this) {if (mState ! STATE_CONNECTED) return;r mConnectedThread;}// Perform the write unsynchronizedr.write(out);}/*** Indicate that the connection attempt failed and notify the UI Activity.*/private void connectionFailed() {// Send a failure message back to the ActivityMessage msg mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST);Bundle bundle new Bundle();bundle.putString(BluetoothChat.TOAST, Unable to connect device);msg.setData(bundle);mHandler.sendMessage(msg);// Start the service over to restart listening modeBluetoothChatService.this.start();}/*** Indicate that the connection was lost and notify the UI Activity.*/private void connectionLost() {// Send a failure message back to the ActivityMessage msg mHandler.obtainMessage(BluetoothChat.MESSAGE_TOAST);Bundle bundle new Bundle();bundle.putString(BluetoothChat.TOAST, Device connection was lost);msg.setData(bundle);mHandler.sendMessage(msg);// Start the service over to restart listening modeBluetoothChatService.this.start();}/*** This thread runs while listening for incoming connections. It behaves* like a server-side client. It runs until a connection is accepted* (or until cancelled).*/private class AcceptThread extends Thread {// The local server socketprivate final BluetoothServerSocket mmServerSocket;private String mSocketType;public AcceptThread(boolean secure) {BluetoothServerSocket tmp null;mSocketType secure ? Secure:Insecure;// Create a new listening server sockettry {if (secure) {tmp mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,MY_UUID_SECURE);} else {tmp mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);}} catch (IOException e) {Log.e(TAG, Socket Type: mSocketType listen() failed, e);}mmServerSocket tmp;}public void run() {if (D) Log.d(TAG, Socket Type: mSocketType BEGIN mAcceptThread this);setName(AcceptThread mSocketType);BluetoothSocket socket null;// Listen to the server socket if were not connectedwhile (mState ! STATE_CONNECTED) {try {// This is a blocking call and will only return on a// successful connection or an exceptionsocket mmServerSocket.accept();} catch (IOException e) {Log.e(TAG, Socket Type: mSocketType accept() failed, e);break;}// If a connection was acceptedif (socket ! null) {synchronized (BluetoothChatService.this) {switch (mState) {case STATE_LISTEN:case STATE_CONNECTING:// Situation normal. Start the connected thread.connected(socket, socket.getRemoteDevice(),mSocketType);break;case STATE_NONE:case STATE_CONNECTED:// Either not ready or already connected. Terminate new socket.try {socket.close();} catch (IOException e) {Log.e(TAG, Could not close unwanted socket, e);}break;}}}}if (D) Log.i(TAG, END mAcceptThread, socket Type: mSocketType);}public void cancel() {if (D) Log.d(TAG, Socket Type mSocketType cancel this);try {mmServerSocket.close();} catch (IOException e) {Log.e(TAG, Socket Type mSocketType close() of server failed, e);}}}/*** This thread runs while attempting to make an outgoing connection* with a device. It runs straight through; the connection either* succeeds or fails.*/private class ConnectThread extends Thread {private final BluetoothSocket mmSocket;private final BluetoothDevice mmDevice;private String mSocketType;public ConnectThread(BluetoothDevice device, boolean secure) {mmDevice device;BluetoothSocket tmp null;mSocketType secure ? Secure : Insecure;// Get a BluetoothSocket for a connection with the// given BluetoothDevicetry {if (secure) {tmp device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);} else {tmp device.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);}} catch (IOException e) {Log.e(TAG, Socket Type: mSocketType create() failed, e);}mmSocket tmp;}public void run() {Log.i(TAG, BEGIN mConnectThread SocketType: mSocketType);setName(ConnectThread mSocketType);// Always cancel discovery because it will slow down a connectionmAdapter.cancelDiscovery();// Make a connection to the BluetoothSockettry {// This is a blocking call and will only return on a// successful connection or an exceptionmmSocket.connect();} catch (IOException e) {// Close the sockettry {mmSocket.close();} catch (IOException e2) {Log.e(TAG, unable to close() mSocketType socket during connection failure, e2);}connectionFailed();return;}// Reset the ConnectThread because were donesynchronized (BluetoothChatService.this) {mConnectThread null;}// Start the connected threadconnected(mmSocket, mmDevice, mSocketType);}public void cancel() {try {mmSocket.close();} catch (IOException e) {Log.e(TAG, close() of connect mSocketType socket failed, e);}}}/*** This thread runs during a connection with a remote device.* It handles all incoming and outgoing transmissions.*/private class ConnectedThread extends Thread {private final BluetoothSocket mmSocket;private final InputStream mmInStream;private final OutputStream mmOutStream;public ConnectedThread(BluetoothSocket socket, String socketType) {Log.d(TAG, create ConnectedThread: socketType);mmSocket socket;InputStream tmpIn null;OutputStream tmpOut null;// Get the BluetoothSocket input and output streamstry {tmpIn socket.getInputStream();tmpOut socket.getOutputStream();} catch (IOException e) {Log.e(TAG, temp sockets not created, e);}mmInStream tmpIn;mmOutStream tmpOut;}public void run() {Log.i(TAG, BEGIN mConnectedThread);byte[] buffer new byte[1024];int bytes;String buffString;// Keep listening to the InputStream while connectedwhile (true) {try {// Read from the InputStreambytes mmInStream.read(buffer);String msgnew String(buffer,0,bytes);buffString msg;int indexOfNewLine buffString.indexOf(\n);if(indexOfNewLine0){String frameString buffString.substring(0, indexOfNewLine1);buffStringbuffString.substring(indexOfNewLine1);mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, frameString).sendToTarget();}if(buffString.length()1024){buffString;}// Send the obtained bytes to the UI Activity // mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer) // .sendToTarget();} catch (IOException e) {Log.e(TAG, disconnected, e);connectionLost();break;}}}/*** Write to the connected OutStream.* param buffer The bytes to write*/public void write(byte[] buffer) {try {mmOutStream.write(buffer);// Share the sent message back to the UI ActivitymHandler.obtainMessage(BluetoothChat.MESSAGE_WRITE, -1, -1, buffer).sendToTarget();} catch (IOException e) {Log.e(TAG, Exception during write, e);}}public void cancel() {try {mmSocket.close();} catch (IOException e) {Log.e(TAG, close() of connect socket failed, e);}}} } View Code   懒样状态图:  转载于:https://www.cnblogs.com/wdfrog/p/4378299.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/912407.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

通过perl或awk实现剪切功能

我有如下文件,我想将第二行的数据,移动到文件的最后一行,如何实现? # cat 1.txt open LOG,">>./a.log"; print LOG "hahh,adfa,adfad"; close LOG;这里我给出了两种方式:AWK和perl语言…

java列队多种实现方式,

在Java中,队列(Queue)是一种常用的数据结构,遵循FIFO(先进先出)原则。Java提供了多种队列实现方式,适用于不同的场景。以下是几种常见的队列实现方式:LinkedList实现 LinkedList实现了Queue接口,可以作为队列…

自定义属性编辑器

自定义属性编辑器需求:将Customer中address属性的值赋值给Address类中的每一个属性 package com.atguigu.selfEditor;public class Address {private String province;private String city;private String town;publi…

Ashampoo Music Studio 12.0.3 音频编辑处理

描述 Ashampoo Music Studio是一个表现良好和强大的工具。它是音频编辑、设计师、创作者和制作人的最爱。该软件是一个集成了视频提取、录制和格式转换的多功能音频处理工具。最新版本还包括创建、编辑和数字管理音乐收…

公司网站优化方案财务软件排行榜前十名

FineReport是一款利用什么语言开发的报表工具? FineReport是一款基于Java语言开发的报表工具。Java是一种广泛使用的编程语言,特别适合于跨平台的软件开发。FineReport利用Java语言的诸多优势,如稳定性、安全性、可移植性和强大的网络功能&a…

建网站html5国外推广网站有什么

在 JavaScript 中,函数内部的 this 关键字是一个特殊的对象,它的值取决于函数被调用的方式。this 可以指向不同的对象,因此在不同的场景中它会有不同的含义。下面是一些常见的场景以及 this 的指向: 全局作用域:当函数…

php网站建设程序模块化wordpress企业主题

WatchBird: 新一代纯PHP防火墙 工具安装 广大研究人员可以使用下列命令直接将项目源码克隆至本地 git clone https://github.com/leohearts/awd-watchbird.git工具部署 1.进入下载好的文件夹目录 2.编译waf.c生成.so文件,参考命令:gcc waf.c -shared -fPIC -o waf.so 3.将w…

河北省招标投标公共服务平台河北网站搜索排名优化方案

1、先在Jenkins安装插件Gitlab Hook Plugin 和Build Authorization Token Root Plugin;2.插件安装完成后在任务里添加token3、在gitlab上添加钩子4、点击测试钩子或push代码再看Jenkins已经在构建了就说明成功了(也可以在浏览器直接执行这个URL&#xff…

网站 内容 营销网站建设骗子公司

7.9 额外实现 7.9.1 任务补偿机制 问题:如果有线程抢占了某个视频的处理任务,如果线程处理过程中挂掉了,该视频的状态将会一直是处理中,其它线程将无法处理,这个问题需要用补偿机制。 单独启动一个任务找到待处理任…

怎么制作网站教程视频广州定制网站开发

JavaScriptSerializer 类由异步通信层内部使用,用于序列化和反序列化在浏览器和 Web 服务器之间传递的数据。说白了就是能够直接将一个C#对象传送到前台页面成为javascript对象。要添加System.Web.Extensions.dll的引用。该类位于System.Web.Script.Serialization命…

上海h5网站建设脑洞大开的创意设计

本项目以Springboot 2.7.11和vue2做参考示例 第一步 展示前后端代码的成品 前端Vue 后端Java 项目写完后,差不多就是这个样子,仅供参考! 第二步 开始打包前后端项目 前端打包的方式有以下几种: 方法1: #直接打包&#xff0…

汽贸公司网站建设抖音代运营介绍

HTTP协议定义了多种请求方法,用于不同的操作。最常见的有 GET、POST 和 PUT。 GET:GET 是最常用的方法,通常用于请求服务器发送某个资源。GET 请求只通过 URL 传送数据,数据信息会附在 URL 之后,以参数的形式附加。由于这种传送方式的限制,GET 请求的数据量较小,且安全性…

工会网站建设请示一级消防工程师考试试题及答案

1、认识Block Block封装了一段代码,可以在任何时候执行Block可以作为函数参数或者函数的返回值,而其本身又可以带输入参数或返回值,它和传统的函数指针很类似,但是有区别:block是inline(内联函数)的&#x…

Gitee:本土化代码托管平台如何重塑中国开发者协作生态

Gitee:本土化代码托管平台如何重塑中国开发者协作生态 在全球化与数字化双重浪潮的冲击下,软件开发行业正经历着前所未有的变革。作为这一变革的核心基础设施,代码托管平台的重要性愈发凸显。在这一领域中,Gitee凭…

详细介绍:麒麟v10服务器安装libvirt

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

WEB项目引入druid监控配置

1、web.xml<!-- 添加Web应用等监控--><filter><filter-name>DruidWebStatFilter</filter-name><filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class><…

Computer Graphics Tutorial

https://www.tutorialspoint.com/computer_graphics/index.htm

网站设计电脑培训学校wordpress导航菜单下拉

原文地址:http://www.dotnetcurry.com/dotnet/1360/concurrent-programming-dotnet-core 今天我们购买的每台电脑都有一个多核心的 CPU&#xff0c;允许它并行执行多个指令。操作系统通过将进程调度到不同的内核来发挥这个结构的优点。然而&#xff0c;还可以通过异步 I/O 操作…

CF1874(CF Round 901) 总结

CF1874(CF Round 901) 总结 A 显然若干轮之后,每两次操作不会改变它们的苹果,于是让 \(K\) 对一个较小数取 \(\min\) 然后暴力做即可。 B 每一位是独立的,对于 \(a,b,m\) 都相同的位,操作后的结果一定相同,所以只…

南通网站建设南通怎么修改网站后台权限

服务器安装IIS&#xff1a; 微软官网下载SDK&#xff1a; 下载Runtime官网&#xff1a;https://dotnet.microsoft.com/download/dotnet-core 安装成功重启IIS&#xff1a; VS发布项目&#xff1a;