Android 蓝牙开发( 二 )

news2024/9/20 20:27:05

前言

上一篇文章给大家分享了Android蓝牙的基础知识和基础用法,不过上一篇都是一些零散碎片化的程序,这一篇给大家分享Android蓝牙开发实战项目的初步使用

效果演示 : 

Android蓝牙搜索,配对,连接,通信

Android蓝牙实战开发步骤

1.新建Android项目添加蓝牙权限

下图所示:MyBluetoothDemo为刚刚创建的Android空项目,我们现在清单文件中把我们需要用到的权限声明一下,其中定位权限还需要做动态申请

2.封装BluetoothAdapter类

BluetoothAdapter类提供了常用的蓝牙API,我这里创建了一个BlueToothController类,小编这里是先将这些API封装到了一个BlueToothController类中,方便后续使用和操作

package com.example.mybluetoothdemo;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.Intent;

import java.util.ArrayList;
import java.util.List;

public class BlueToothController {

    private BluetoothAdapter mBluetoothAdapter;

    public BlueToothController(){
        //初始化蓝牙适配器
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    public BluetoothAdapter getBluetoothAdapter() {
        return mBluetoothAdapter;
    }




    /**
     * 检查设备是否支持蓝牙
     */
    public boolean isBluetoothSupport(){
        if(mBluetoothAdapter == null){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 检查该设备蓝牙是否开启
     */
    public boolean isBluetoothEnabled(){
        if(mBluetoothAdapter.isEnabled()){
            return true;
        }else {
            return false;
        }
    }


    /**
     * 打开蓝牙
     */
    @SuppressLint("MissingPermission")
    public void turnOnBlueTooth(Activity activity, int requestCode) {
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        activity.startActivityForResult(intent, requestCode);
    }


    /**
     * 打开蓝牙可见性
     */
    @SuppressLint("MissingPermission")
    public void enableVisibily(Context context){
        Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,300);
        context.startActivity(intent);
    }


    /**
     * 停止查找设备
     */
    @SuppressLint("MissingPermission")
    public void cancelFindDevice(){
        mBluetoothAdapter.cancelDiscovery();
    }

    /**
     * 判断当前设备是否在查找蓝牙设备
     */
    @SuppressLint("MissingPermission")
    public boolean isStartDiscovering(){
        if(mBluetoothAdapter.isDiscovering()){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 判断当前设备是否未在查找蓝牙设备
     */
    @SuppressLint("MissingPermission")
    public boolean isCancelDiscovering(){
        if(!mBluetoothAdapter.isDiscovering()){
            return true;
        }else {
            return false;
        }
    }


    /**
     * 查找设备
     */
    @SuppressLint("MissingPermission")
    public void findDevice() {
        mBluetoothAdapter.startDiscovery();
    }


    /**
     * 获取已绑定设备
     */
    @SuppressLint("MissingPermission")
    public List<BluetoothDevice> getBondedDeviceList(){
        return new ArrayList<>(mBluetoothAdapter.getBondedDevices());
    }

    /**
     * 判断蓝牙是否连接
     */
    @SuppressLint("MissingPermission")
    public boolean isConnectBlue(BluetoothSocket bluetoothSocket){
        return bluetoothSocket !=null && bluetoothSocket.isConnected();
    }
}

3. 编写UI页面

activity_main.xml:这是我们MainActivity的UI,放置了一个ListView和一个按钮,ListView用来显示搜索到的蓝牙设备和已配对的蓝牙设备,Button控件用来与连接后的设备发送信息时使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16.dp"
    android:paddingRight="16.dp"
    android:paddingBottom="16.dp">

    <ListView
        android:id="@+id/device_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#e90423"
        android:dividerHeight="1px"
        >
    </ListView>

    <Button
        android:id="@+id/btn_write_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:text="发送消息"/>

</RelativeLayout>

既然有了ListView,那就一定有ListView的每条子元素UI,新建list_item.xml

list_item.xml:    用来显示ListView列表的子内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:textStyle="bold"
            android:textSize="18sp"/>

        <TextView android:id="@+id/text3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:textSize="13sp"/>

    </LinearLayout>

</LinearLayout>

然后,我们再为页面右上角写一个menu列表按钮,新建menu_main.xml

menu_main.xml:  

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".MainActivity" >

    <item
        android:id="@+id/is_bluetooth_support"
        android:title="@string/is_bluetooth_support"
        android:orderInCategory="1" />

    <item
        android:id="@+id/is_bluetooth_enabled"
        android:title="@string/is_bluetooth_enabled"
        android:orderInCategory="2" />

    <item
        android:id="@+id/bonded_device"
        android:title="@string/bonded_device"
        android:orderInCategory="2" />

    <item
        android:id="@+id/find_device"
        android:title="@string/find_device"
        android:orderInCategory="3" />


</menu>

最后,再为大家分享一下string.xml字符串配置信息

4. 蓝牙列表适配器

创建DeviceAdapter类,具体如下图所示:

package com.example.mybluetoothdemo;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class DeviceAdapter extends BaseAdapter{

    private List<BluetoothDevice> mData;
    private Context mContext;

    public DeviceAdapter(List<BluetoothDevice> data, Context context){
        mData = data;
        mContext = context.getApplicationContext();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("MissingPermission")
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View itemView = view;
        //复用view,优化性能
        if(itemView == null){
            itemView = LayoutInflater.from(mContext).inflate(R.layout.list_item, viewGroup,false);
        }


        TextView text1 = itemView.findViewById(R.id.text1);
        TextView text2 = itemView.findViewById(R.id.text3);

        text1.setTextColor(Color.BLACK);
        text2.setTextColor(Color.BLACK);

        //获取对应的蓝牙设备
        BluetoothDevice device = (BluetoothDevice) getItem(i);


        //显示设备名称
        if(device.getName()==null){
            text1.setText("N/A");
        }else {
            text1.setText(device.getName());
        }

        //显示设备地址
        text2.setText(device.getAddress());

        return itemView;
    }

    //刷新列表,防止搜索结果重复出现
    public void refresh(List<BluetoothDevice> data){
        mData = data;
        notifyDataSetChanged();
    }

}

5. 蓝牙搜索,配对,连接,通信

小编这里为了让大家方便,便将搜索,配对,连接都写在了MainActivity中了

package com.example.mybluetoothdemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class MainActivity extends AppCompatActivity {

    private final String TAG = "yf";

    private BlueToothController blueToothController = new BlueToothController();

    private static final int REQUEST_ENABLE_BT = 1;

    private ListView listView;
    private DeviceAdapter blueToothDeviceAdapter,bondBlueToothDeviceAdapter;

    private List<BluetoothDevice> deviceList = new ArrayList<>();
    private List<BluetoothDevice> bondedDeviceList = new ArrayList<>();

    private BluetoothDevice device;

    private BluetoothGatt bluetoothGatt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initUI();

        //判断是否有访问位置的权限,没有权限,直接申请位置权限
        isPermission();


        registerBluetoothReceiver();
    }



    @SuppressLint("MissingPermission")
    private void initUI(){
        listView = findViewById(R.id.device_list);
        blueToothDeviceAdapter = new DeviceAdapter(deviceList,this);
        bondBlueToothDeviceAdapter = new DeviceAdapter(bondedDeviceList,this);

        findViewById(R.id.btn_write_1).setOnClickListener(view -> {
            if (null == mWriter){
                Log.e("cx12345","ble:发送失败:null == writer !!!!");
            }else {
                mWriter.setValue(new byte[]{
                        (byte)0x0c,
                        (byte)0x11,
                        (byte)0x09,
                        (byte)0x41,
                        (byte)0x23,
                        (byte)0x00,
                        (byte)0x01,
                        (byte)0x03,
                        (byte)0xFF
                });

                mGatt.writeCharacteristic(mWriter);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main,menu);
        return true;
    }

    @SuppressLint("MissingPermission")
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        switch (id){
            case R.id.is_bluetooth_support:
                if (blueToothController.isBluetoothSupport()){
                    Toast.makeText(MainActivity.this, "该设备支持蓝牙功能", Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(MainActivity.this, "该设备不支持蓝牙功能", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.is_bluetooth_enabled:
                if (blueToothController.isBluetoothEnabled()){
                    Toast.makeText(MainActivity.this, "蓝牙已开启", Toast.LENGTH_SHORT).show();
                }else {
                    blueToothController.turnOnBlueTooth(this,REQUEST_ENABLE_BT);
                }
                break;
            case R.id.bonded_device:
                setTitle("已配对的设备");

                bondedDeviceList = blueToothController.getBondedDeviceList();
                listView.setAdapter(bondBlueToothDeviceAdapter);
                bondBlueToothDeviceAdapter.refresh(bondedDeviceList);


                break;
            case R.id.find_device:
                setTitle("可用设备");
                if(blueToothController.isStartDiscovering()){
                    blueToothController.cancelFindDevice();
                }
                blueToothController.findDevice();
//                blueToothController.getBluetoothAdapter().startLeScan(leScanCallback);
                listView.setAdapter(blueToothDeviceAdapter);
                blueToothDeviceAdapter.refresh(deviceList);
                listView.setOnItemClickListener(deviceBluetooth);
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    private AdapterView.OnItemClickListener deviceBluetooth = new AdapterView.OnItemClickListener() {
        @SuppressLint("MissingPermission")
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            device = deviceList.get(i);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                //蓝牙绑定
//                device.createBond();

                //Gatt协议连接蓝牙
                bluetoothGatt = device.connectGatt(MainActivity.this,true,mGattCallback);
                bluetoothGatt.connect();
            }
        }
    };




    //动态获取位置权限
    private void isPermission(){
        if ((checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
                || (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 200);
        }
    }




    @SuppressLint("MissingPermission")
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 停止设备搜索
        blueToothController.getBluetoothAdapter().cancelDiscovery();
        //注销广播
        unregisterReceiver(receiver);
    }


    private void registerBluetoothReceiver(){
        //filter注册广播接收器
        IntentFilter filter = new IntentFilter();


        //蓝牙当前状态
        filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);


        //开始扫描蓝牙设备广播
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);

        //找到蓝牙设备广播
        filter.addAction(BluetoothDevice.ACTION_FOUND);

        //扫描蓝牙设备结束广播
        filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);

        //蓝牙设备配对状态改变广播
        filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);

        //设备扫描模式改变广播
        filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);

        registerReceiver(receiver, filter);
    }

    //处理找到蓝牙设备和搜索完成的广播消息
    BroadcastReceiver receiver = new BroadcastReceiver() {

        @SuppressLint("MissingPermission")
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            //开始查找设备
            if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)){
                //初始化适配器列表
                deviceList.clear();
                bondedDeviceList.clear();
                blueToothDeviceAdapter.refresh(deviceList);
                bondBlueToothDeviceAdapter.refresh((bondedDeviceList));
            }
            //找到蓝牙设备
            else if(BluetoothDevice.ACTION_FOUND.equals(action)){
                //搜到蓝牙设备
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

                    //把搜索到的设备添加到已找到列表中,显示它的信息
                    deviceList.add(device);
                    blueToothDeviceAdapter.refresh(deviceList);

            }
            //查找设备结束
            else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
                //搜索完毕
                Toast.makeText(MainActivity.this, "选择要配对的蓝牙设备", Toast.LENGTH_SHORT).show();
                blueToothDeviceAdapter.refresh(deviceList);
            }
            //配对状态
            else if(BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if(device == null){
                    Toast.makeText(MainActivity.this, "无设备", Toast.LENGTH_SHORT).show();
                    return;
                }

                int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,0);
                if(state == BluetoothDevice.BOND_BONDED){
                    Toast.makeText(MainActivity.this, "已配对", Toast.LENGTH_SHORT).show();
                }else if(state == BluetoothDevice.BOND_BONDING){
                    Toast.makeText(MainActivity.this, "正在配对", Toast.LENGTH_SHORT).show();
                }else if(state == BluetoothDevice.BOND_NONE){
                    Toast.makeText(MainActivity.this, "未配对", Toast.LENGTH_SHORT).show();
                }
            }

        }
    };

    private BluetoothGatt mGatt;
    private BluetoothGattCharacteristic mWriter;

    /**
     * @param gatt     返回连接建立的gatt对象
     * @param status   返回的是此次gatt操作的结果,成功了返回0
     * @param newState 每次client连接或断开连接状态变化,
     *                 STATE_CONNECTED 0,
     *                 STATE_CONNECTING 1,
     *                 STATE_DISCONNECTED 2,
     *                 STATE_DISCONNECTING 3
     */

    private BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
        @SuppressLint("MissingPermission")
        @Override
        public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {

            //连接成功
            if(newState == BluetoothProfile.STATE_CONNECTED){
                //进行服务发现
                gatt.discoverServices();
                Log.d(TAG,"连接成功");
            }else if(newState == BluetoothProfile.STATE_DISCONNECTED){
                //连接断开,处理断开逻辑
                Log.d(TAG,"连接断开");
            }
        }

        @SuppressLint("MissingPermission")
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            Log.d(TAG,"onServicesDiscovered : " + status + " ==>> " + gatt.toString());

            //发现服务成功,处理服务和特征值
            if(status == BluetoothGatt.GATT_SUCCESS){
                //发送消息
                mGatt = gatt;
                BluetoothGattService service = gatt.getService(UUID.fromString("0000180a-0000-1000-8000-00805F9B34FB"));
                mWriter = service.getCharacteristic(UUID.fromString("00002ad9-0000-1000-8000-00805F9B34FB"));

                //打开消息通知
                mGatt.setCharacteristicNotification(mWriter,true);
                BluetoothGattDescriptor descriptor = mWriter.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
                descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
                mGatt.writeDescriptor(descriptor);
            }else {
                Log.d(TAG,"发现服务失败");
            }

        }


        @Override
        public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
            Log.e(TAG,"onCharacteristicRead " + status);
            //读取特征成功,处理特征值
            if(status == BluetoothGatt.GATT_SUCCESS){

            }
        }

        @Override
        public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
            Log.e(TAG,"onCharacteristicWrite " + status);
            //写入特征成功
            if(status == BluetoothGatt.GATT_SUCCESS){
                Log.d(TAG,"发送成功");
            }else {
                Log.d(TAG,"发送失败");
            }
        }

        @Override
        public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {

            //接收到数据
            byte[] data = characteristic.getValue();

            //处理接收到的数据
            Log.d(TAG,"Received data: " + bytesToHexFun2(data));
        }

        @Override
        public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
            super.onDescriptorRead(gatt, descriptor, status);
        }

        @Override
        public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
            super.onDescriptorWrite(gatt, descriptor, status);
        }

        @Override
        public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
            super.onReliableWriteCompleted(gatt, status);
        }

        @Override
        public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
            super.onReadRemoteRssi(gatt, rssi, status);
        }

        @Override
        public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
            super.onMtuChanged(gatt, mtu, status);
        }

        @Override
        public void onServiceChanged(@NonNull BluetoothGatt gatt) {
            super.onServiceChanged(gatt);
        }

        @Override
        public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
            super.onPhyUpdate(gatt, txPhy, rxPhy, status);
        }

        @Override
        public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
            super.onPhyRead(gatt, txPhy, rxPhy, status);
        }
    };

    private char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    private  String bytesToHexFun2(byte[] bytes) {
        char[] buf = new char[bytes.length * 2];
        int index = 0;
        for(byte b : bytes) { // 利用位运算进行转换,可以看作方法一的变种
            buf[index++] = HEX_CHAR[b >>> 4 & 0xf];
            buf[index++] = HEX_CHAR[b & 0xf];
        }

        return new String(buf);
    }

}

到此为止,我们的程序就到这里了,蓝牙搜索,配对,连接,通信便已经成功实现了,大家可以把代码copy一下拿去运行,具体效果演示图在文章最上方,大家还想了解更多关于Android蓝牙开发的可以继续看我下一篇给大家的分享

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

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

相关文章

数据包的处理流程

一个数据包从发送到接收都经历了那些过程 1.启动应用程序新建邮件&#xff0c;将收件人邮箱和邮件内容填写好&#xff0c;应用程序进行编码处理。&#xff08;应用层&#xff09; 2.应用在发送邮件那一刻建立TCP连接&#xff08;三次握手&#xff09;&#xff0c;将数据交给传…

在Nodejs中使用JWT进行鉴权

什么是 JSON Web Token&#xff08;JWT&#xff09;&#xff1f; JSON Web Token&#xff08;JWT&#xff09;是一种用于在web上传递信息的标准&#xff0c;它以JSON格式表示信息&#xff0c;通常用于身份验证和授权。 JWT由三个部分组成&#xff1a;Header&#xff08;头部&…

五、MySQL(DML)如何连接到DataGrip?并显示所有数据库?

前提&#xff1a;已经配置好DataGrip&#xff0c;并创建好一个项目&#xff1a; 1、选择数据库&#xff1a; 点击左上角加号&#xff0c;再选择数据源&#xff0c;选择MySQL数据源&#xff1a; 2、填写信息&#xff1a; 用户栏填写&#xff1a;root 密码填写&#xff1a;你…

算法设计 || 第9题:0-1背包问题动态规划(手写例题+源代码)

&#xff08;一&#xff09;背包问题知识点&#xff1a; &#xff08;二&#xff09;经典测试题&#xff1a; 已知n8种&#xff0c;每种一件。背包最大负载M110。 重量w和价值v如下表&#xff0c;怎样装价值最大?贪心算法 求X[N]最优解&#xff0c;写出求解过程;强化为0/1背包…

基于clip驱动的器官分割和肿瘤检测通用模型

论文&#xff1a;https://arxiv.org/abs/2301.00785 我看这篇主要是看看MRI的多模态融合方法的&#xff0c;所以会略一些东西&#xff0c;感兴趣细节的就翻原文好嘞 摘要 越来越多的公共数据集在自动器官分割和肿瘤检测方面显示出显著的影响。然而&#xff0c;由于每个数据集…

冠达管理:股票减持是什么意思?2023减持新规?

在a股商场上&#xff0c;大股东一般会进行大宗买卖、减持来影响股价&#xff0c;那么&#xff0c;股票减持是什么意思&#xff1f;2023减持新规&#xff1f;下面冠达管理为我们准备了相关内容&#xff0c;以供参阅。 ​ 股票减持是指上市公司持股比例较高的股东出售所持股份以…

ARM-M0 + 24bit 高精度ADC,采样率4KSPS,国产新品,传感器首选

ARM-M0内核MCU 内置24bit ADC &#xff0c;采样率4KSPS flash 64KB&#xff0c;SRAM 32KB 适用于传感器&#xff0c;电子秤&#xff0c;体脂秤等等

【爬虫】5.6 Selenium等待HTML元素

任务目标 在浏览器加载网页的过程中&#xff0c;网页的有些元素时常会有延迟的现象&#xff0c;在HTML元素还没有准备好的情况下去操作这个HTML元素必然会出现错误&#xff0c;这个时候Selenium需要等待HTML元素。例如&#xff1a;上节实例中出现的select的下拉框元素&#xff…

htmx-使HTML更强大

‍本文作者是360奇舞团开发工程师 htmx 让我们先来看一段俳句: javascript fatigue: longing for a hypertext already in hand 这个俳句很有意思&#xff0c;是开源项目htmx文档中写的&#xff0c;意思是说&#xff0c;我们已经有了超文本&#xff0c;为什么还要去使用javascr…

1、Spring是什么?

Spring 是一款主流的 Java EE 轻量级开源框架 。 框架 你可以理解为是一个程序的半成品&#xff0c;它帮我们实现了一部分功能&#xff0c;用这个框架我们可以减少代码的实现和功能的开发。 开源 也就是说&#xff0c;它开放源代码。通过源代码&#xff0c;你可以看到它是如何…

【问题思考总结】为什么B树中的搜索可以在分支结点上结束,而B+树必须到叶节点上才能结束?

问题提出 在刷到B树的时候&#xff0c;发现王道书上写B树非叶子结点仅仅起到索引作用&#xff0c;没有关键字对应记录的存储地址。 然而&#xff0c;观察B树的存储结构&#xff0c;我们发现&#xff0c;其中对于每个结点&#xff0c;也仅有结点的关键字信息和指向子树的指针…

SpringBoot—日志

目录 日志使用日志日志级别设置日志级别设置分组指定日志文件路径日志切割归档使用第三方日志框架log4j2配置文件【分级存储】logback配置文件【分级存储】 实例代码 日志 使用日志 给controller添加日志信息 要给controller类上添加Slf4j注解&#xff0c;然后使用log.info(…

Android 开发中的sdkmanager 操作说明(Delphi适用)

目录 sdkmanager 说明&#xff1a; 用法&#xff1a; 列出已安装和可用的软件包 安装软件包 更新所有已安装的软件包 接受许可 选项 sdkmanager 说明&#xff1a; sdkmanager 是一个命令行工具&#xff0c;您可以用它来查看、安装、更新和卸载 Android SDK 的软件包。如…

前端文件、图片直传OOS、分片上传、el-upload上传(vue+elementUI)

前言&#xff1a;基于天翼云的面相对象存储(Object-Oriented Storage&#xff0c;OOS),实现小文件的直接上传&#xff0c;大文件的分片上传。 开发文档地址&#xff1a;网址 上传之前的相关操作&#xff1a;注册账户&#xff0c;创建 AccessKeyId 和 AccessSecretKey之后&…

Private market:借助ZK实现的任意计算的trustless交易

1. 引言 Private market&#xff0c;借助zk-SNARKs和以太坊来 隐私且trustlessly selling&#xff1a; 1&#xff09;以太坊地址的私钥&#xff08;ECDSA keypair&#xff09;2&#xff09;EdDSA签名3&#xff09;Groth16 proof&#xff1a;借助递归性来匿名交易Groth16 proo…

RTK和CORS有什么区别?

高精度定位技术 关于高精度定位技术&#xff0c;RTK为业界熟知且被广泛应用&#xff0c;那么RTK到底是什么&#xff1f;仅仅是差分GPS吗&#xff1f; 其实并不尽然。 RTK RTK&#xff0c;载波相位差分技术&#xff0c;是实时处理两个测站载波相位观测量的差分方法&#xff0…

什么是OLAP

一、什么是OLAP OLAP&#xff08;On-line Analytical Processing&#xff0c;联机分析处理&#xff09;是在基于数据仓库多维模型的基础上实现的面向分析的各类操作的集合。可以比较下其与传统的OLTP&#xff08;On-line Transaction Processing&#xff0c;联机事务处理&…

分布式集群框架——Google文件系统GFS

Google文件系统GFS Google文件系统&#xff08;Google File System&#xff0c;GFS&#xff09;是一个大型的分布式文件系统。它为Google云计算提供海量存储&#xff0c;并且与Chubby、MapReduce以及Bigtable等技术结合十分紧密&#xff0c;处于所有核心技术的底层。由于GFS并不…

TDesign表单rules通过函数 实现复杂逻辑验证输入内容

Element ui 中 我们可以通过validator 绑定函数来验证一些不在表单model中的值 又或者处理一下比较复杂的判断逻辑 TDesign也有validator 但比较直观的说 没有Element那么好用 这里 我们给validator绑定了我们自己的checkAge函数 这个函数中 只有一个参数 value 而且 如果你的…

ssm计算机网络课程试卷生成器系统源码

ssm计算机网络课程试卷生成器系统源码099 开发工具&#xff1a;idea 数据库mysql5.7 数据库链接工具&#xff1a;navcat,小海豚等 技术&#xff1a;ssm package com.controller;import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays;…