Android BLE 在不知道蓝牙设备的Notify特征的情况下如何接收数据

之前有个设备,使用nRFConnect工具扫描出了所有的UUID,然后通过Notify的特征值实现了接收数据。今天忽然换了个不知道从哪儿找来的设备,居然扫描不出Notify。但是用nRFConnect工具依然可以收到数据,而且还是通过Notify的方式。这就很懵了,现在这个设备用我自己的代码是能发数据,但是不能接收数据。可否给个思路,图在下面~~~然后多句嘴,这个设备是老板(兼硬件)不知道从哪儿翻出来的,估计是很久以前的库存,为了节约成本已经决定用这款设备了,问他一问三不知……图片说明

1个回答

不能接受数据是因为权限没给

在回调里面重写onServicesDiscovered

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        super.onServicesDiscovered(gatt, status);
        Log.e(TAG, "onServicesDiscovered gatt = " + gatt);
        if (status == BluetoothGatt.GATT_SUCCESS) { 
            String address = gatt.getDevice().getAddress(); 
            threadSleep(200);
            displayGattServices(gatt, address); 
        }  
    } //发现所连接设备的服务和特征

对所有的特征都付给权限,肯定能行(我这里是对特征的uuid做了过滤,你不知道UUID的情况下可以不过滤,对所有的特征都赋权限)

private void displayGattServices(BluetoothGatt gatt, String address) { 
    List<BluetoothGattService> gattServices = getSupportedGattServices(gatt);
    if (gattServices == null) return;
    String uuid = null;
    for (BluetoothGattService gattService : gattServices) {
        // 列表中有(gattServices) gattServices 此处遍历每一个gattService 找到单片机的通知特征 打开通知(后续就可以自动接到消息)
        uuid = gattService.getUuid().toString();
        Log.e(TAG, "displayGattServices uuid = " + uuid);
        if (uuid.equals(SERVICE_UUID)) {
            mReadCharacteristic = gattService.getCharacteristic(UUID.fromString(NOTIFICATION_UUID));
            mWriteCharacteristic = gattService.getCharacteristic(UUID.fromString(WRITE_UUID)); 
        }
    } 
    if (mReadCharacteristic != null) {
        final int charaProp = mReadCharacteristic.getProperties();
        if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
            Log.e(TAG, "displayGattServices PROPERTY_READ > 0 ");
            readCharacteristic(gatt, mReadCharacteristic);
        }
        threadSleep(1000);
        if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
            Log.e(TAG, "displayGattServices PROPERTY_NOTIFY > 0 ");
            setCharacteristicNotification(gatt, mReadCharacteristic, true);
        }
    } else {
        Log.w(TAG, "unable to find NOTIFICATION_UUID");
    }
}

赋权限方法如下

public void readCharacteristic(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    if (gatt == null || mBluetoothAdapter == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    } 
    gatt.readCharacteristic(characteristic);
}

public void setCharacteristicNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, boolean enable) {
    if (gatt == null || mBluetoothAdapter == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    } 
    gatt.setCharacteristicNotification(characteristic, enable);
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    gatt.writeDescriptor(descriptor);   
}
liqin19870815
liqin19870815 回复谁把我名字用了!: 好吧 你搞定了就OK
7 个月之前 回复
baidu_36743221
谁把我名字用了! 回复liqin19870815: 哥呀,权限是一定要有的。但是你这个代码不是赋值权限,是订阅读取通知,你只有setCharacteristicNotification了才能在回调里收到设备发给你的消息哈。
7 个月之前 回复
liqin19870815
liqin19870815 回复: public static String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
7 个月之前 回复
liqin19870815
liqin19870815 CLIENT_CHARACTERISTIC_CONFIG 这个值是通用的好像
7 个月之前 回复
baidu_36743221
谁把我名字用了! 我这个问题的关键点是没有CLIENT_CHARACTERISTIC_CONFIG的UUID,从别人博客里复制了一个居然就可以了。
7 个月之前 回复
liqin19870815
liqin19870815 这段代码很重要,权限一定要赋,还有延迟也是必不可少的
7 个月之前 回复
liqin19870815
liqin19870815 if (mReadCharacteristic != null) { final int charaProp = mReadCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { Log.e(TAG, "displayGattServices PROPERTY_READ > 0 "); readCharacteristic(gatt, mReadCharacteristic); } threadSleep(1000); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { Log.e(TAG, "displayGattServices PROPERTY_NOTIFY > 0 "); setCharacteristicNotification(gatt, mReadCharacteristic, true); }
7 个月之前 回复
liqin19870815
liqin19870815 能发数据不能接受数据,这个问题上次困了我三天,
7 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android中ble蓝牙只能接受20字节问题

在android使用ble蓝牙接受数据时,默认只能接受和发送20字节,但是现在接受的数据大于20字节,该怎么处理?参考网上调用requestMtu方法无效,以下为部分代码与sdk版本,请大神帮忙看下什么问题![图片说明](https://img-ask.csdn.net/upload/202003/10/1583821426_212186.jpg)![图片说明](https://img-ask.csdn.net/upload/202003/10/1583821433_911884.jpg)

mac、ios、android蓝牙BLE通信

大家好,跟大家咨询下mac、ios、android蓝牙ble通信的问题。 问题是这样的:前几天写个小程序,mac、ios端使用的sdk是CoreBluetooth 一台mac端作为中央设备,另一台mac做外围设备、iphone和android手机做为外设。mac与mac电脑、iphone之间使用ble聊天正常。anroid手机端与iphone之间通过blueligh测试收发消息正常,但mac与android手机通信出现问题,android能收到mac电脑发送到消息,但mac电脑收不到android手机发送的消息。跟踪mac端代码发现时发现中央设备连接上外设后,扫描外设服务,遍历到自己定义的特征,然后将该特征设为notify时失败了。即 [peripheral setNotifyValue:YES forCharacteristic:characteristic]失败。但在回调函数中 - (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic: (CBCharacteristic *)characteristic error:(NSError *)error 中error是未知错误。 不知道大家遇到这种情况没,大神们出来交流下吧

android开发BLE蓝牙时蓝牙连接不稳定会自动断开重连

搜索、通讯均正常,只是连接不正常 public void onCreate(){ super.onCreate(); // Initializes a Bluetooth adapter. For API level 18 and above, get a reference to // BluetoothAdapter through BluetoothManager. final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE); mBluetoothAdapter = bluetoothManager.getAdapter(); // Checks if Bluetooth is supported on the device. if (mBluetoothAdapter == null) { Toast.makeText(this, "没有蓝牙", Toast.LENGTH_SHORT).show(); stopSelf(); return; } if(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)){ Toast.makeText(this, "不支持BLE", Toast.LENGTH_SHORT).show(); stopSelf(); return; } } @Override public void onDestroy(){ if(mBluetoothGatt != null){ mBluetoothGatt.close(); } mBluetoothGatt = null; super.onDestroy(); } @Override public boolean onUnbind(Intent intent){ if(mBluetoothGatt != null){ mBluetoothGatt.close(); } mBluetoothGatt = null; return super.onUnbind(intent); } // Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) { String str = device.getName() + "|" + device.getAddress(); LogUtil.d(TAG, "get BluetoothDevice.ACTION_FOUND:" + str); sendLocalBroadcast(ACTION_SCAN_FOUND,str); } }; public void startScan(){ Handler mHandler = new Handler(); mHandler.postDelayed(new Runnable() { @Override public void run() { stopScan(); } },SCAN_PERIOD ); LogUtil.d(TAG, "get startScan"); mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback); sendLocalBroadcast(ACTION_SCAN_STARTED); } public void stopScan(){ if(mScanning){ LogUtil.d(TAG, "get stopScan"); mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); sendLocalBroadcast(ACTION_SCAN_FINISHED); } } public void findService(List<BluetoothGattService> gattServices) { Log.i(TAG, "Count is:" + gattServices.size()); for (BluetoothGattService gattService : gattServices) { Log.i(TAG, gattService.getUuid().toString()); Log.i(TAG, UUID_SERVICE.toString()); if(gattService.getUuid().toString().equalsIgnoreCase(UUID_SERVICE.toString())) { List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); Log.i(TAG, "Count is:" + gattCharacteristics.size()); for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) { if(gattCharacteristic.getUuid().toString().equalsIgnoreCase(UUID_NOTIFY.toString())) { Log.i(TAG, gattCharacteristic.getUuid().toString()); Log.i(TAG, UUID_NOTIFY.toString()); mNotifyCharacteristic = gattCharacteristic; setCharacteristicNotification(gattCharacteristic, true); //broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); return; } } } } } // Implements callback methods for GATT events that the app cares about. For example, // connection change and services discovered. //设备连接 private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { String intentAction; Log.i(TAG, "oldStatus=" + status + " NewStates=" + newState); if(status == BluetoothGatt.GATT_SUCCESS) { if (newState == BluetoothProfile.STATE_CONNECTED) { intentAction = ACTION_CONNECTED; sendLocalBroadcast(intentAction); Log.i(TAG, "Connected to GATT server."); // Attempts to discover services after successful connection. Log.i(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices()); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { intentAction = ACTION_DISCONNECTED; mBluetoothGatt.close(); mBluetoothGatt = null; Log.i(TAG, "Disconnected from GATT server."); sendLocalBroadcast(intentAction); } } } //发现服务 @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { Log.w(TAG, "onServicesDiscovered received: " + status); findService(gatt.getServices()); } else { if(mBluetoothGatt.getDevice().getUuids() == null) Log.w(TAG, "onServicesDiscovered received: " + status); } } @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { byte[] bufRecv = characteristic.getValue(); int nRecv = bufRecv.length; if(nRecv > 1024 + nReadPtr - nRecvPtr) nRecv = 1024 + nReadPtr - nRecvPtr; if(nRecv + nRecvPtr <= 1024){ System.arraycopy(bufRecv, 0, bRecv, nRecvPtr, nRecv); nRecvPtr += nRecv; } else{ System.arraycopy(bufRecv, 0, bRecv, nRecvPtr, 1024-nRecvPtr); System.arraycopy(bufRecv, 1024-nRecvPtr, bRecv, 0, nRecv - (1024-nRecvPtr)); nRecvPtr = nRecv - (1024 - nRecvPtr); } sendLocalBroadcast(ACTION_DATA_RECV); } } /** * 发送数据后的回调 * @param gatt * @param characteristic * @param status */ @Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { Log.e(TAG, "OnCharacteristicWrite"); } @Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor bd, int status) { Log.e(TAG, "onDescriptorRead"); } @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { byte[] bufRecv = characteristic.getValue(); int nRecv = bufRecv.length; if(nRecv > 1024 + nReadPtr - nRecvPtr) nRecv = 1024 + nReadPtr - nRecvPtr; if(nRecv + nRecvPtr <= 1024){ System.arraycopy(bufRecv, 0, bRecv, nRecvPtr, nRecv); nRecvPtr += nRecv; } else{ System.arraycopy(bufRecv, 0, bRecv, nRecvPtr, 1024-nRecvPtr); System.arraycopy(bufRecv, 1024-nRecvPtr, bRecv, 0, nRecv - (1024-nRecvPtr)); nRecvPtr = nRecv - (1024 - nRecvPtr); } sendLocalBroadcast(ACTION_DATA_RECV); Log.e(TAG, "onCharacteristicChanged"); } @Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor bd, int status) { Log.e(TAG, "onDescriptorWrite"); } @Override public void onReadRemoteRssi(BluetoothGatt gatt, int a, int b) { Log.e(TAG, "onReadRemoteRssi"); } @Override public void onReliableWriteCompleted(BluetoothGatt gatt, int a) { Log.e(TAG, "onReliableWriteCompleted"); } @Override public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) { Log.e(TAG, "onMtuChanged"); } }; public boolean connect(final String address){ if (mBluetoothAdapter == null || address == null) { Log.w(TAG, "BluetoothAdapter not initialized or unspecified address."); return false; } BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); if (device == null) { Log.w(TAG, "Device not found. Unable to connect."); return false; } // We want to directly connect to the device, so we are setting the autoConnect // parameter to false. if(mBluetoothGatt != null) { mBluetoothGatt.close(); mBluetoothGatt = null; } mBluetoothGatt = device.connectGatt(this, false, mGattCallback); Log.d(TAG, "Trying to create a new connection."); return true; } public void disconnect(){ if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.disconnect(); } @Override public int read(byte[] data) { int readLen = data.length; int bufLen; int retLen; if(nRecvPtr >= nReadPtr) bufLen = nRecvPtr - nReadPtr; else bufLen = nRecvPtr + 1024 - nReadPtr; if(readLen <= bufLen) retLen = readLen; else retLen = bufLen; if(nReadPtr + retLen < 1024){ System.arraycopy(bRecv, nReadPtr, data,0,retLen); nReadPtr += retLen; } else{ System.arraycopy(bRecv, nReadPtr, data, 0, 1024-nReadPtr); System.arraycopy(bRecv, 0, data, 1024-nReadPtr, retLen - (1024-nReadPtr)); nReadPtr = retLen-(1024-nReadPtr); } return retLen; } public byte[] write(byte[] data){ mNotifyCharacteristic.setValue(data/*strValue.getBytes()*/); mBluetoothGatt.writeCharacteristic(mNotifyCharacteristic); LogUtil.i(TAG, "12154123164512332465451218451231654561233545612"); //return data.length; return data; } public final void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { byte[] value = characteristic.getValue(); Log.d(TAG, "onCharacteristicChanged: " + value); String s0 = Integer.toHexString(value[0] & 0xFF); String s = Integer.toHexString(value[1] & 0xFF); Log.d(TAG, "onCharacteristicChanged: " + s0 + "、" + s); for (byte b : value) { Log.d(TAG, "onCharacteristicChanged: " + b); } } /** * Request a read on a given {@code BluetoothGattCharacteristic}. The read result is reported * asynchronously through the {@code BluetoothGattCallback#onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)} * callback. * * @param characteristic The characteristic to read from. */ public void readCharacteristic(BluetoothGattCharacteristic characteristic) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.readCharacteristic(characteristic); } /** * Enables or disables notification on a give characteristic. * * @param characteristic Characteristic to act on. * @param enabled If true, enable notification. False otherwise. */ public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) { if (mBluetoothAdapter == null || mBluetoothGatt == null) { Log.w(TAG, "BluetoothAdapter not initialized"); return; } mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); /* // This is specific to Heart Rate Measurement. if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) { BluetoothGattDescriptor descriptor = characteristic.getDescriptor( UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); mBluetoothGatt.writeDescriptor(descriptor); } */ } /** * Retrieves a list of supported GATT services on the connected device. This should be * invoked only after {@code BluetoothGatt#discoverServices()} completes successfully. * * @return A {@code List} of supported services. */ public List<BluetoothGattService> getSupportedGattServices() { if (mBluetoothGatt == null) return null; return mBluetoothGatt.getServices(); } } ``` ```

android ble蓝牙广播问题!!!!!!!!!!!!!!!!!!

使用ble蓝牙开发 在写入数据之后 设备返回的数据证明发送成功了 但是在广播中也会返回数据,我这边接收不到 使用别人的demo 可以接收到数据 这里有demo 哪位大哥帮忙看看代码有没有什么问题。 ``` package com.example.andysong.nuclearradiation.Ble; 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.companion.BluetoothDeviceFilter; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; import com.example.andysong.nuclearradiation.Ble.Adapter.MyAdapter; import com.example.andysong.nuclearradiation.Ble.BleTool.MyBluetoothDevice; import com.example.andysong.nuclearradiation.Ble.Entity.BleData; import com.example.andysong.nuclearradiation.R; import com.example.andysong.nuclearradiation.Uitl.Progess.DialProgress; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; public class BleActivityTest extends AppCompatActivity implements View.OnClickListener, MyAdapter.OnScan { private static final String TAG = BleActivityTest.class.getName(); private Button btn_scan; private Button btn_w; private RecyclerView rv_list; private MyAdapter myAdapter; private BluetoothAdapter bAdapter; private BluetoothGatt bluetoothGatt; private Map<String, UUID> uuidMap; //private UUID uNotify = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID N_Notify = UUID.fromString("0000ffe0-0000-1000-8000-00805f9b34fb"); private UUID N_Notify = UUID.fromString("00001000-0000-1000-8000-00805f9b34fb"); //private UUID uNotify = UUID.fromString("0000ffe4-0000-1000-8000-00805f9b34fb"); private UUID uNotify = UUID.fromString("00001002-0000-1000-8000-00805f9b34fb"); //private UUID uRead = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID uWrite = UUID.fromString("6e400003-b5a3-f393-e0a9-e50e24dcca9e"); //private UUID N_Write = UUID.fromString("0000ffe5-0000-1000-8000-00805f9b34fb"); private UUID N_Write = UUID.fromString("00001000-0000-1000-8000-00805f9b34fb"); private static final UUID CLIENT_CHARACTERISTIC_CONFIG = UUID.fromString( "00002902-0000-1000-8000-00805f9b34fb"); //private UUID uWrite = UUID.fromString("0000ffe9-0000-1000-8000-00805f9b34fb"); private UUID uWrite = UUID.fromString("00001001-0000-1000-8000-00805f9b34fb"); private String READ = "read"; private String WRITE = "write"; private String NOTICE = "notice"; private Button btn_r; private Button btn_n; private Button btn_c; private DialProgress dialProgress; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ble); initView(); initData(); } private void initView() { btn_scan = findViewById(R.id.btn_scan); btn_w = findViewById(R.id.btn_w); btn_r = findViewById(R.id.btn_r); btn_n = findViewById(R.id.btn_n); btn_c = findViewById(R.id.btn_c); btn_scan.setOnClickListener(this); btn_w.setOnClickListener(this); btn_r.setOnClickListener(this); btn_n.setOnClickListener(this); btn_c.setOnClickListener(this); rv_list = findViewById(R.id.rv_list); rv_list.setLayoutManager(new LinearLayoutManager(this, LinearLayout.VERTICAL, false)); myAdapter = new MyAdapter(this); myAdapter.setOnScan(this); rv_list.setAdapter(myAdapter); dialProgress = findViewById(R.id.dialprog); } private void initData() { bAdapter = BluetoothAdapter.getDefaultAdapter(); uuidMap = new HashMap<>(); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_scan: scan(); break; case R.id.btn_w: writeData(); break; case R.id.btn_r: readData(); break; case R.id.btn_n: notifyData(); break; case R.id.btn_c: closeNotifyData(); break; } } /*关闭广播通知*/ private void closeNotifyData() { BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); } /*打开广播通知*/ private void notifyData() { BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify); boolean b = bluetoothGatt.setCharacteristicNotification(characteristic, true); int originalWriteType = characteristic.getWriteType(); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); boolean b1 = bluetoothGatt.writeDescriptor(descriptor); characteristic.setWriteType(originalWriteType); } /*read 读取数据 返回的数据需要在监听事件接收*/ private void readData() { if (bluetoothGatt == null) { return; } BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(UUID.fromString("00001000-0000-1000-8000-00805f9b34fb")). getCharacteristic(UUID.fromString("00001001-0000-1000-8000-00805f9b34fb")); bluetoothGatt.readCharacteristic(characteristic); } /*扫描设备*/ private void scan() { if (!bAdapter.isEnabled()) { Toast.makeText(this, "请打开蓝牙", Toast.LENGTH_SHORT).show(); return; } bAdapter.startLeScan(scanCallback); btn_scan.setText("扫描中"); btn_scan.setEnabled(false); } /*扫描到新的设备*/ private BluetoothAdapter.LeScanCallback scanCallback = new BluetoothAdapter.LeScanCallback() { @Override public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { MyBluetoothDevice bluetoothDevice = new MyBluetoothDevice(device, rssi); addDevice(bluetoothDevice); // Log.e(TAG, "onLeScan: " + device.getAddress() + device.getName()); if (device.getAddress().equals("F6:6D:83:80:D6:8D")) { conn(bluetoothDevice); } //F6:6D:83:80:D6:8D } }; /*添加扫描的新设备*/ private void addDevice(MyBluetoothDevice bluetoothDevice) { List<MyBluetoothDevice> devices = myAdapter.getDevices(); for (MyBluetoothDevice device : devices) { if (device.getDevice().getAddress().equals(bluetoothDevice.getDevice().getAddress())) { return; } } myAdapter.upDate(bluetoothDevice); } /*item点击链接的方法*/ @Override public void conn(MyBluetoothDevice device) { bluetoothGatt = device.getDevice().connectGatt(this, false, mBluetoothGattCallback); } /*写数据 数据不会直接返回 需要在监听事件中回调*/ public void writeData() { if (bluetoothGatt == null) { return; } // bluetoothGatt.readRemoteRssi(); BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Write).getCharacteristic(uWrite); //characteristic.setValue("E5015101003420"); characteristic.setValue("EF52FFFAFFFF"); //characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); bluetoothGatt.writeCharacteristic(characteristic); } /*链接状态—ready—write-*/ BluetoothGattCallback mBluetoothGattCallback = new BluetoothGattCallback() { //链接状态更改时 @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { gatt.discoverServices(); //查询支持的服务 bluetoothGatt = gatt; BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { btn_scan.setVisibility(View.GONE); btn_w.setVisibility(View.VISIBLE); btn_r.setVisibility(View.VISIBLE); btn_n.setVisibility(View.VISIBLE); btn_c.setVisibility(View.VISIBLE); } }); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { Log.e(TAG, "onConnectionStateChange: 断开"); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { btn_scan.setEnabled(true); } }); } btn_scan.setText("扫描"); } //读取数据 @Override public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicRead(gatt, characteristic, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "读取成功"); printALL(characteristic.getValue()); } else { Log.e(TAG, "读取失败"); } } //写出数据返回状态 @Override public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { super.onCharacteristicWrite(gatt, characteristic, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onCharacteristicWrite发送成功"); printALL(characteristic.getValue()); } else { Log.e(TAG, "onCharacteristicWrite发送失败"); } } /*一般情况是 给设备发送指令使用应该*/ @Override public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { super.onDescriptorRead(gatt, descriptor, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onDescriptorRead读取成功"); printALL(descriptor.getValue()); } else { Log.e(TAG, "onDescriptorRead读取失败"); } } /*一般情况是 给设备发送指令使用应该*/ @Override public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) { super.onDescriptorWrite(gatt, descriptor, status); bluetoothGatt = gatt; if (status == BluetoothGatt.GATT_SUCCESS) { Log.e(TAG, "onDescriptorWrite发送成功"); printALL(descriptor.getValue()); } else { Log.e(TAG, "onDescriptorWrite发送失败"); } } /*接收通知 广播后 接收到的数据在这里*/ @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { //super.onCharacteristicChanged(gatt, characteristic); //bluetoothGatt = gatt; byte[] value = characteristic.getValue(); try { String s=new String(value,"UTF-8"); Log.e(TAG, "onCharacteristicChanged: "+s); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } printNotify(value); } //返回信号强度的 @Override public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) { super.onReadRemoteRssi(gatt, rssi, status); bluetoothGatt = gatt; Log.e(TAG, "onReadRemoteRssi: " + rssi); } //返回支持的服务滴 @Override public void onServicesDiscovered(BluetoothGatt gatt, int status) { super.onServicesDiscovered(gatt, status); bluetoothGatt = gatt; read(gatt); } }; public void read(BluetoothGatt gatt) { List<BluetoothGattService> services = gatt.getServices(); for (BluetoothGattService service : services) { Log.e(TAG, "服务: " + service.getUuid() + "-----"); List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics(); for (BluetoothGattCharacteristic characteristic : characteristics) { if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) > 0) { uuidMap.put(READ, characteristic.getUuid()); Log.e(TAG, "读写属性: " + characteristic.getUuid()); for (BluetoothGattDescriptor bluetoothGattDescriptor:characteristic.getDescriptors()){ Log.e(TAG, "蓝牙描述符+++: " + bluetoothGattDescriptor.getUuid()); } } if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) { uuidMap.put(WRITE, characteristic.getUuid()); Log.e(TAG, "写属性: " + characteristic.getUuid()); } if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { uuidMap.put(NOTICE, characteristic.getUuid()); Log.e(TAG, "通知属性: " + characteristic.getUuid()); for (BluetoothGattDescriptor bluetoothGattDescriptor : characteristic.getDescriptors()) { Log.e(TAG, "蓝牙描述符: " + bluetoothGattDescriptor.getUuid()); } } } } Set<String> strings = uuidMap.keySet(); for (String key : strings) { UUID uuid = uuidMap.get(key); Log.e(TAG, "list: " + uuid.toString()); } } private void printALL(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { sb.append(Integer.toHexString(b[i]) + " "); } Log.e(TAG, "printALL--------: " + sb.toString()); } private void printALL2(final byte[] b) { Log.e(TAG, "printALL2--------: " + byteToString(b)); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { dialProgress.setValue2(Double.parseDouble(formatString(byteToString(b)).getData())); } }); } private void printNotify(final byte[] b) { Log.e(TAG, "printNotify--------: " + byteToString(b)); BleActivityTest.this.runOnUiThread(new Runnable() { @Override public void run() { dialProgress.setValue2(Double.parseDouble(formatString(byteToString(b)).getData())); } }); } /*显示给客户*/ private String byteToString(byte[] b) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; i++) { String s = String.valueOf(b[i]).replace("-", ""); String s1 = Integer.toHexString(Integer.valueOf(s)); if (i == 0 || i == 1) { char c = asciiToChar(Integer.valueOf(s)); sb.append(c + " "); continue; } else if (s1.length() == 1) { sb.append("0" + s1 + " "); continue; } sb.append(s1 + " "); } return sb.toString(); } /*ascii 转 字符*/ private char asciiToChar(int a) { return (char) a; } /*代码用来计算的数据*/ private BleData formatString(String v) { String value = v.replace(" ", ""); String command = value.substring(0, 2); String date = value.substring(2, 8); String company = value.substring(8, 10); String d = value.substring(10, 18); StringBuffer data = new StringBuffer(); boolean flag = true; for (int i = 0; i < d.length(); i++) { if (i == 0) { continue; } if (i % 2 != 0) { if (flag) { data.append(Integer.valueOf(d.substring(0, i + 1)) + "."); flag = false; } else { data.append(Integer.valueOf(d.substring(i - 1, i + 1))); } } } String crc = value.substring(18, value.length()); return new BleData(command, date, company, data.toString(), crc); } }; ```

Android BLE接收发送数据

各位大神,BLE连接成功,写入数据也成功了,但是onCharacteristicNotification()这个方法一直不回调,狠头疼呀,不知道是个什么问题。是不是与读与写的代码前后顺序有关系?是不是还和特征值的notify有关系?求各位大神的指导,最好能有读与写的源码解释,感谢各位大神莅临指导,感谢~感谢~~![图片说明](http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/001/face/1.gif)

android 5.1 下 BLE 通信问题

android5.1 下 使用ble扫描设备,发现设备后,进行连接,程序会调用: 1.onConnectionStateChange 2.onServicesDiscovered 然后,在发送数据的时候,程序又会像上面一样走一遍...导致发送出去的数据丢包一样.不完整. 主机无法解析...就好比23个字节的数据发出去,只发了20,然后后面再发,它又多了N个字节,就是找不到规律.乱七八糟的..... 我使用小米.系统5.0的,运行很流畅. 酷派的也正常. 现在发现华为和魅族的手机都是这个样子. 我以为是我程序问题, 我使用BLE设备生产厂家的APP源码调试也是这样的. 请问大家有遇到这样的问题吗?

安卓蓝牙BLE只能发送数据,不能接收数据,求教求教!

用的QN9021蓝牙模块,串口助手监控; ![图片说明](https://img-ask.csdn.net/upload/201602/16/1455633053_721235.png) 找到能够发送数据的characteristic,发送数据,串口助手收到数据 ![图片说明](https://img-ask.csdn.net/upload/201602/16/1455633137_465921.png) ![图片说明](https://img-ask.csdn.net/upload/201602/16/1455633201_988068.png) 串口助手发送数据,接收数据总是null或者0,接收不到数据 ![图片说明](https://img-ask.csdn.net/upload/201602/16/1455633298_320514.png) 所有的characteristic都试过了,还是不能读到数据,十分困惑,求教!!!

Android ble开发BluetoothGattCharacteristic

Android BluetoothGattCharacteristic类中的property和permission的区别,具体有什么相同点和不同点。应该怎样设置。

关于蓝牙4.0 BLE读取电量的问题

private void displayGattServices(List<BluetoothGattService> gattServices){ if(gattServices == null) return; String uuid = null; for(BluetoothGattService gattService : gattServices){ uuid = gattService.getUuid().toString(); if(uuid.equalsIgnoreCase(BATTERY_SERVICE)){ String uuid_charas = null; List<BluetoothGattCharacteristic> gattCharacteristics = gattService.getCharacteristics(); for(BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics){ uuid_charas = gattCharacteristic.getUuid().toString(); if(uuid_charas.equalsIgnoreCase(BATTERY_CHARATERISTIC)){ final int charaProp = gattCharacteristic.getProperties(); if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) { if (mNotifyCharacteristic != null) { mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false); mNotifyCharacteristic = null; } mBluetoothLeService.readCharacteristic(gattCharacteristic); } if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { mNotifyCharacteristic = gattCharacteristic; mBluetoothLeService.setCharacteristicNotification(gattCharacteristic, true); } } } } } } private void broadcastUpdate(String action,BluetoothGattCharacteristic characteristic){ final Intent intent = new Intent(action); if(UUID_HEART_RATE_MEASUREMENT.equals(characteristic .getUuid())){ int flag = characteristic.getProperties(); int format = -1; if((flag&0x01) != 0){ format = BluetoothGattCharacteristic.FORMAT_UINT16; }else { format = BluetoothGattCharacteristic.FORMAT_UINT8; } final int heartRate = characteristic.getIntValue(format,1); intent.putExtra(EXTRA_DATA,String.valueOf(heartRate)); }else { final byte[] data = characteristic.getValue(); if(data != null && data.length >0){ final StringBuilder stringBuilder = new StringBuilder(data.length); for(byte byteChar: data) stringBuilder.append(String.format("%02X",byteChar)); intent.putExtra(EXTRA_DATA,new String(data)+"\n"+stringBuilder.toString()); } } sendBroadcast(intent); } 读取到了电量的特征值,但是显示d 64,怎么让它解析成百分比的形式显示在text文本?求各位大侠拔刀相助!~

ble 蓝牙在Read方法中读取数据每次只能读取一次,怎么做可以循环读取?

ble蓝牙开发中我们onServicesDiscovered()方法中遍历服务后并且设置数据,然后再onCharacteristicRead()方法中读取数据,然而在读取的方法中每次只能自动读取一次,只有当有数据变化时才会再次读取,但是我想一次读取多个数据,不需要其他的操作,代码怎么实现?下面是我在读取方法中写的,每次只能读取一个数据。求大神帮帮忙? ``` List<BluetoothGattService> services = gatt.getServices(); for (BluetoothGattService s : services) { List<BluetoothGattCharacteristic> gattCharacteristicss = s.getCharacteristics(); for (int i = 0; i < gattCharacteristicss.size(); i++) { BluetoothGattCharacteristic gattCharacteristic = gattCharacteristicss.get(i); Log.e("000", "gattCharacteristicss:" + i + ":" + gattCharacteristic.getUuid().toString()); if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .GAMESIR_BLE_CHARACTERISTICS_X1_Manifacturer)) { try { manifacturer = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "Manifacturer:" + manifacturer); } // if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .GAMESIR_BLE_CHARACTERISTICS_X1_Software)) { try { software = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "Software:" + software); } else if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .dISHardwareREV_UUID)) { try { hardware = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "Hardware:" + hardware); // } else if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .GAMESIR_BLE_CHARACTERISTICS_X1_FIRMWARE)) { try { version = new String(gattCharacteristic.getValue(), "UTF-8"); Log.e("000", "firmware_version数据1:" + version); UpdateUiUtil.setFirmWare(version); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //////// } else if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .dISSerialNR_UUID)) { try { serial = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "Serial:" + serial); } else if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .dISModelNR_UUID)) { try { model = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "Model:" + model); // } else if (gattCharacteristic.getUuid().toString().equals(SampleGattAttributes .dISSystemID_UUID)) { try { systemID = new String(gattCharacteristic.getValue(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.e("000", "SystemID:" + systemID); } ```

蓝牙Ble通知回调发送命令之后没反应,onCharacteristicChanged

在发送命令之后,onCharacteristicChanged这个回调里面接收不到数据 打开通知 ``` /*打开广播通知*/ private void notifyData() { BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Notify).getCharacteristic(uNotify); BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); bluetoothGatt.writeDescriptor(descriptor); bluetoothGatt.setCharacteristicNotification(characteristic, true); } ``` 发送数据 ``` public void writeData() { if (bluetoothGatt == null) { return; } BluetoothGattCharacteristic characteristic = bluetoothGatt.getService(N_Write).getCharacteristic(uWrite); characteristic.setValue("EF52FFFAFFFF"); bluetoothGatt.writeCharacteristic(characteristic); } ``` 接收通知 ``` @Override public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { super.onCharacteristicChanged(gatt, characteristic); bluetoothGatt = gatt; byte[] value = characteristic.getValue(); try { String s=new String(value,"UTF-8"); Log.e(TAG, "onCharacteristicChanged: "+s); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } printNotify(value); } ```

安卓设备如何监听蓝牙的连接状态

如题,在我的APP中,成功将手机连接上了一个蓝牙串口,现在想监听它们之间的连接状态。在网上找到的方式都是用BroadcastReceiver来监听蓝牙状态改变的广播,于是我实现了这种方式,代码部分如下: private void registerBoradcastReceiver() { IntentFilter stateChangeFilter = new IntentFilter( BluetoothAdapter.ACTION_STATE_CHANGED); IntentFilter connectedFilter = new IntentFilter( BluetoothDevice.ACTION_ACL_CONNECTED); IntentFilter disConnectedFilter = new IntentFilter( BluetoothDevice.ACTION_ACL_DISCONNECTED); registerReceiver(stateChangeReceiver, stateChangeFilter); registerReceiver(stateChangeReceiver, connectedFilter); registerReceiver(stateChangeReceiver, disConnectedFilter); } private BroadcastReceiver stateChangeReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (BluetoothDevice.ACTION_ACL_CONNECTED == action) { showchange(action); } if (BluetoothDevice.ACTION_ACL_DISCONNECTED == action) { showchange(action); } if (BluetoothAdapter.ACTION_STATE_CHANGED == action) { showchange(action); } } }; 但是调试的时候并没有监听到任何的状态变化,求指教。

大学课程设计,编写蓝牙透传app时候,再发送一个信息蓝牙就断开连接

如题,我最近在做课程设计,题目是基于STM32的一个猫屋设计,主要是一个PWM风扇控制,和一个远程投喂功能。 再加个基于BT05的蓝牙透传APP。APP做到一半,PWM风扇做好了,但是想加个定时远程投喂加不上,思路是定时中断STM32,从而达到投喂功能。 1. 遇到的问题:APP能设置温度的上下限,读取实时温度,上下限温度。但是再想读取一个投喂间隔或者设置投喂间隔就会自动断开蓝牙连接![图片说明](https://img-ask.csdn.net/upload/201905/07/1557219048_675317.jpg) 这是我的APP界面。就是如果读取投喂间隔或者按最后一个按钮——设置投喂间隔,就会断开蓝牙,返回扫描蓝牙界面。 请各位前辈指教。我不知道怎么修改。 下面是我的DeviceCnotrolActivity.java的代码。谢谢。 ``` /* * Copyright (C) 2013 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.bluetooth.le; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattService; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.TextView; import android.widget.Toast; /** * For a given BLE device, this Activity provides the user interface to connect, display data, * and display GATT services and characteristics supported by the device. The Activity * communicates with {@code BluetoothLeService}, which in turn interacts with the * Bluetooth LE API. */ public class DeviceControlActivity extends Activity { private final static String TAG = DeviceControlActivity.class.getSimpleName(); public static final String EXTRAS_DEVICE_NAME = "DEVICE_NAME"; public static final String EXTRAS_DEVICE_ADDRESS = "DEVICE_ADDRESS"; private TextView mConnectionState; private TextView mDataField; private TextView mDataTemptured;//显示温度 private TextView mSetTemptured;//设置温度 private TextView mSetLTemptured;//设置温度 下限 private TextView mFenSuRang;//风扇档位 private String mDeviceName; private String mDeviceAddress; private ExpandableListView mGattServicesList; private BluetoothLeService mBluetoothLeService; private ArrayList<ArrayList<BluetoothGattCharacteristic>> mGattCharacteristics = new ArrayList<ArrayList<BluetoothGattCharacteristic>>(); private boolean mConnected = false; private BluetoothGattCharacteristic mNotifyCharacteristic; boolean connect_status_bit=false; private final String LIST_NAME = "NAME"; private final String LIST_UUID = "UUID"; private final String g_TitleName = "智能温度控制设计"; private final String g_EndByte= "0E"; private final String g_SetHADDR = "0A0B02"; private final String g_SetLADDR = "0A0B03"; private Handler mHandler; // Stops scanning after 10 seconds. private static final long SCAN_PERIOD = 1000; private int i = 0; private int TIME = 1000; // Code to manage Service lifecycle. private final ServiceConnection mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName componentName, IBinder service) { mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService(); if (!mBluetoothLeService.initialize()) { Log.e(TAG, "Unable to initialize Bluetooth"); finish(); } // Automatically connects to the device upon successful start-up initialization. mBluetoothLeService.connect(mDeviceAddress); } @Override public void onServiceDisconnected(ComponentName componentName) { mBluetoothLeService = null; } }; // Handles various events fired by the Service. // ACTION_GATT_CONNECTED: connected to a GATT server. // ACTION_GATT_DISCONNECTED: disconnected from a GATT server. // ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services. // ACTION_DATA_AVAILABLE: received data from the device. This can be a result of read // or notification operations. private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) { //mConnected = true; connect_status_bit=true; invalidateOptionsMenu(); } else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) { mConnected = false; updateConnectionState(R.string.disconnected); connect_status_bit=false; show_view(false); invalidateOptionsMenu(); clearUI(); } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) { // Show all the supported services and characteristics on the user interface. displayGattServices(mBluetoothLeService.getSupportedGattServices()); } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) { displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA)); } } }; // If a given GATT characteristic is selected, check for supported features. This sample // demonstrates 'Read' and 'Notify' features. See // http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for the complete // list of supported characteristic features. private final ExpandableListView.OnChildClickListener servicesListClickListner = new ExpandableListView.OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { return false; } }; private void clearUI() { //mGattServicesList.setAdapter((SimpleExpandableListAdapter) null); mDataField.setText(R.string.no_data); } Button send_button; //发送上限温度按键 Button send_Lowbutton; //发送下限温度按键 Button send_feedbutton; //发送投喂按键 Button enable_button; Button IBeacon_set_button; EditText txd_txt,uuid_1001_ed; EditText txd_txtLowTempture; //下限显示文本 EditText txd_txtfeedtime; //投喂间隔显示文本 EditText ibeacon_uuid; EditText mayjor_txt,minor_txt; EditText dev_Name; Button name_button; EditText password_ed;//密码值 Button password_enable_bt;//密码开关 Button password_wrt;//密码写入Button Button adv_time1,adv_time2,adv_time3,adv_time4; boolean pass_en=false; Button clear_button; private Button IO_H_button,IO_L_button;//out io Timer timer = new Timer(); void show_view( boolean p ) { if(p){ send_button.setEnabled(true); send_Lowbutton.setEnabled(true); send_feedbutton.setEnabled(true); }else{ send_button.setEnabled(false); send_Lowbutton.setEnabled(false); send_feedbutton.setEnabled(false); } } public void delay(int ms){ try { Thread.currentThread(); Thread.sleep(ms); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gatt_services_characteristics); final Intent intent = getIntent(); mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME); mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS); // Sets up UI references. ((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress); //mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list); // mGattServicesList.setOnChildClickListener(servicesListClickListner); mConnectionState = (TextView) findViewById(R.id.connection_state); // mDataField = (TextView) findViewById(R.id.data_value); mDataTemptured = (TextView) findViewById(R.id.rx_Tempture); mSetTemptured= (TextView) findViewById(R.id.ARM_Tempture); mSetLTemptured= (TextView) findViewById(R.id.L_Tempture); mFenSuRang= (TextView) findViewById(R.id.rx_FenRang); send_button=(Button)findViewById(R.id.tx_SetHbutton);//send data 1002 send_button.setOnClickListener(listener);//设置监听 send_Lowbutton = (Button)findViewById(R.id.tx_SetLbutton);//send data 1002 send_Lowbutton.setOnClickListener(listener);//设置监听 send_feedbutton=(Button)findViewById(R.id.tx_SetFbutton);//send data 1002 send_feedbutton.setOnClickListener(listener);//设置监听 // clear_button=(Button)findViewById(R.id.clear_button);//send data 1002 // clear_button.setOnClickListener(listener);//设置监听 txd_txt=(EditText)findViewById(R.id.tx_text);//1002 data txd_txt.setText("28"); txd_txtLowTempture=(EditText)findViewById(R.id.tx_dispLTemptuer);//1002 data txd_txtLowTempture.setText("15"); // rx_data_id_1=(EditText)findViewById(R.id.rx_data_id_1);//1002 data // rx_data_id_1.setText(""); show_view(false); mHandler = new Handler(); timer.schedule(task, 1000, 1000); // 1s后执行task,经过1s再次执行 boolean sg; getActionBar().setTitle(g_TitleName); // getActionBar().setDisplayHomeAsUpEnabled(true); Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); sg = bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE); //getActionBar().setTitle( "="+BluetoothLeService ); //mDataField.setText("="+sg ); updateConnectionState(R.string.connecting);//更新连接状态 } Handler handler = new Handler() { public void handleMessage(Message msg) { if (msg.what == 1) { //tvShow.setText(Integer.toString(i++)); //scanLeDevice(true); if (mBluetoothLeService != null) { if( mConnected==false ) { updateConnectionState(R.string.connecting); final boolean result = mBluetoothLeService.connect(mDeviceAddress); Log.d(TAG, "Connect request result=" + result); } } } super.handleMessage(msg); }; }; TimerTask task = new TimerTask() { @Override public void run() { // 需要做的事:发送消息 Message message = new Message(); message.what = 1; handler.sendMessage(message); } }; Button.OnClickListener listener = new Button.OnClickListener(){//创建监听对象 public void onClick(View v){ //String strTmp="点击Button02"; //Ev1.setText(strTmp); switch( v.getId()) { case R.id.tx_SetHbutton ://uuid1002 数传通道发送数据 设置上限按钮 if( connect_status_bit ) { String tx_string=txd_txt.getText().toString().trim(); //去掉有空格 mBluetoothLeService.txxx(g_SetHADDR+tx_string+g_EndByte); }else{ //Toast.makeText(this, "Deleted Successfully!", Toast.LENGTH_LONG).show(); Toast toast = Toast.makeText(DeviceControlActivity.this, "设备没有连接!", Toast.LENGTH_SHORT); toast.show(); } break; case R.id.tx_SetLbutton ://uuid1002 数传通道发送数据 设置下限按钮 if( connect_status_bit ) { String tx_string=txd_txtLowTempture.getText().toString().trim(); //去掉有空格 mBluetoothLeService.txxx(g_SetLADDR+tx_string+g_EndByte); }else{ //Toast.makeText(this, "Deleted Successfully!", Toast.LENGTH_LONG).show(); Toast toast = Toast.makeText(DeviceControlActivity.this, "设备没有连接!", Toast.LENGTH_SHORT); toast.show(); } break; case R.id.tx_SetFbutton ://uuid1002 数传通道发送数据 设置上限按钮 if( connect_status_bit ) { String tx_string=txd_txtfeedtime.getText().toString().trim(); //去掉有空格 mBluetoothLeService.txxx(g_SetHADDR+tx_string+g_EndByte); }else{ //Toast.makeText(this, "Deleted Successfully!", Toast.LENGTH_LONG).show(); Toast toast = Toast.makeText(DeviceControlActivity.this, "设备没有连接!", Toast.LENGTH_SHORT); toast.show(); } break; // case R.id.clear_button: // { //// len_g =0; //// da = ""; //// rx_data_id_1.setText( da ); //// mDataField.setText( ""+len_g ); // }break; default : break; } } }; @Override protected void onResume() { super.onResume(); registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter()); if (mBluetoothLeService != null) { final boolean result = mBluetoothLeService.connect(mDeviceAddress); Log.d(TAG, "Connect request result=" + result); } } @Override protected void onPause() { super.onPause(); unregisterReceiver(mGattUpdateReceiver); } @Override protected void onDestroy() { super.onDestroy(); unbindService(mServiceConnection); mBluetoothLeService = null; timer.cancel(); timer=null; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.gatt_services, menu); if (mConnected) { menu.findItem(R.id.menu_connect).setVisible(false); menu.findItem(R.id.menu_disconnect).setVisible(true); } else { menu.findItem(R.id.menu_connect).setVisible(true); menu.findItem(R.id.menu_disconnect).setVisible(false); } return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.menu_connect: mBluetoothLeService.connect(mDeviceAddress); return true; case R.id.menu_disconnect: mBluetoothLeService.disconnect(); return true; case android.R.id.home: onBackPressed(); return true; } return super.onOptionsItemSelected(item); } private void updateConnectionState(final int resourceId) { runOnUiThread(new Runnable() { @Override public void run() { mConnectionState.setText(resourceId); } }); } String da=""; int len_g = 0; private void displayData( String data1 ) { //String head1,data_0; /* head1=data1.substring(0,2); data_0=data1.substring(2); */ //da = da+data1+"\n"; if( data1!=null&&data1.length()>0) { //mDataField.setText( data1 ); //len_g += data1.length()/2; //da = data1+da; //rx_data_id_1.setText( data1 ); // mDataField.setText( ""+len_g ); mDataTemptured.setText(data1.substring(4, 6)+"℃"); mSetTemptured.setText(data1.substring(6, 8)+"℃"); mSetLTemptured.setText(data1.substring(8, 10)+"℃"); mFenSuRang.setText(data1.substring(10, 12)+"档"); //rx_data_id_1.setGravity(Gravity.BOTTOM); //rx_data_id_1.setSelection(rx_data_id_1.getText().length()); } } // Demonstrates how to iterate through the supported GATT Services/Characteristics. // In this sample, we populate the data structure that is bound to the ExpandableListView // on the UI. private void displayGattServices(List<BluetoothGattService> gattServices) { if (gattServices == null) return; if( gattServices.size()>0&&mBluetoothLeService.get_connected_status( gattServices )>=4 ) { if( connect_status_bit ) { mConnected = true; show_view( true ); mBluetoothLeService.enable_JDY_ble(true); try { Thread.currentThread(); Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } mBluetoothLeService.enable_JDY_ble(true); updateConnectionState(R.string.connected); }else{ //Toast.makeText(this, "Deleted Successfully!", Toast.LENGTH_LONG).show(); Toast toast = Toast.makeText(DeviceControlActivity.this, "设备没有连接!", Toast.LENGTH_SHORT); toast.show(); } } // SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter( // this, // gattServiceData, // android.R.layout.simple_expandable_list_item_2, // new String[] {LIST_NAME, LIST_UUID}, // new int[] { android.R.id.text1, android.R.id.text2 }, // gattCharacteristicData, // android.R.layout.simple_expandable_list_item_2, // new String[] {LIST_NAME, LIST_UUID}, // new int[] { android.R.id.text1, android.R.id.text2 } // ); // // mGattServicesList.setAdapter(gattServiceAdapter); } private static IntentFilter makeGattUpdateIntentFilter() { final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED); intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED); intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED); intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE); return intentFilter; } } ```

关于蓝牙4.0通讯的问题

01-05 19:49:34.526: E/AndroidRuntime(11183): FATAL EXCEPTION: main 01-05 19:49:34.526: E/AndroidRuntime(11183): Process: com.example.myble, PID: 11183 01-05 19:49:34.526: E/AndroidRuntime(11183): java.lang.RuntimeException: Error receiving broadcast Intent { act=BLE_DATA_NOTIFY flg=0x10 (has extras) } in com.Feng.myble.MainActivity$2@41cc1f88 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:797) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.os.Handler.handleCallback(Handler.java:733) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.os.Handler.dispatchMessage(Handler.java:95) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.os.Looper.loop(Looper.java:136) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.app.ActivityThread.main(ActivityThread.java:5336) 01-05 19:49:34.526: E/AndroidRuntime(11183): at java.lang.reflect.Method.invokeNative(Native Method) 01-05 19:49:34.526: E/AndroidRuntime(11183): at java.lang.reflect.Method.invoke(Method.java:515) 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871) 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 01-05 19:49:34.526: E/AndroidRuntime(11183): at dalvik.system.NativeStart.main(Native Method) 01-05 19:49:34.526: E/AndroidRuntime(11183): Caused by: java.lang.ArrayIndexOutOfBoundsException: length=6; index=6 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.Feng.myble.MainActivity.shortSignedAtOffset(MainActivity.java:576) 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.Feng.myble.MainActivity.access$14(MainActivity.java:574) 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.Feng.myble.MainActivity$2$1.run(MainActivity.java:539) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.app.Activity.runOnUiThread(Activity.java:4783) 01-05 19:49:34.526: E/AndroidRuntime(11183): at com.Feng.myble.MainActivity$2.onReceive(MainActivity.java:399) 01-05 19:49:34.526: E/AndroidRuntime(11183): at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:782) 01-05 19:49:34.526: E/AndroidRuntime(11183): ... 9 more 在连接到蓝牙设备之后,程序崩溃,输出以上的log。但是这个程序在我更换蓝牙连接的传感器之前是没有出现过问题的

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

为什么本科以上学历的人只占中国人口的5%,但感觉遍地都是大学生?

中国大学生占总人口不到5% 2017年,中国整体的本科率仅有5.9%;如果算上研究生,这一比例可以进一步上升到6.5% 为什么在国家统计局推出的这份年鉴中,学历的最高一阶就是到研究生,而没有进一步再统计博士生的数量的。 原因其实并不难理解,相比全国和各省整体人口体量,博士生的占比非常之低,属于绝对意义上的小概率样本。 这一点,我们从上表中的各省研究生占比情况也可以看出端倪。除北京、天津、上海三...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

记录下入职中软一个月(外包华为)

我在年前从上一家公司离职,没想到过年期间疫情爆发,我也被困在家里,在家呆着的日子让人很焦躁,于是我疯狂的投简历,看面试题,希望可以进大公司去看看。 我也有幸面试了我觉得还挺大的公司的(虽然不是bat之类的大厂,但是作为一名二本计算机专业刚毕业的大学生bat那些大厂我连投简历的勇气都没有),最后选择了中软,我知道这是一家外包公司,待遇各方面甚至不如我的上一家公司,但是对我而言这可是外包华为,能...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

6年开发经验女程序员,面试京东Java岗要求薪资28K

写在开头: 上周面试了一位女程序员,上午10::30来我们部门面试,2B哥接待了她.来看看她的简历: 个人简历 个人技能: ● 熟悉spring mvc 、spring、mybatis 等框架 ● 熟悉 redis 、rocketmq、dubbo、zookeeper、netty 、nginx、tomcat、mysql。 ● 阅读过juc 中的线程池、锁的源...

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

都前后端分离了,咱就别做页面跳转了!统统 JSON 交互

文章目录1. 无状态登录1.1 什么是有状态1.2 什么是无状态1.3 如何实现无状态1.4 各自优缺点2. 登录交互2.1 前后端分离的数据交互2.2 登录成功2.3 登录失败3. 未认证处理方案4. 注销登录 这是本系列的第四篇,有小伙伴找不到之前文章,松哥给大家列一个索引出来: 挖一个大坑,Spring Security 开搞! 松哥手把手带你入门 Spring Security,别再问密...

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

97年世界黑客编程大赛冠军作品(大小仅为16KB),惊艳世界的编程巨作

这是世界编程大赛第一名作品(97年Mekka ’97 4K Intro比赛)汇编语言所写。 整个文件只有4095个字节, 大小仅仅为16KB! 不仅实现了3D动画的效果!还有一段震撼人心的背景音乐!!! 内容无法以言语形容,实在太强大! 下面是代码,具体操作看最后! @echo off more +1 %~s0|debug e100 33 f6 bf 0 20 b5 10 f3 a5...

程序员是做全栈工程师好?还是专注一个领域好?

昨天,有位大一的同学私信我,说他要做全栈工程师。 我一听,这不害了孩子么,必须制止啊。 谁知,讲到最后,更确定了他做全栈程序员的梦想。 但凡做全栈工程师的,要么很惨,要么很牛! 但凡很牛的,绝不是一开始就是做全栈的! 全栈工程师听起来好听,但绝没有你想象的那么简单。 今天听我来给你唠,记得帮我点赞哦。 一、全栈工程师的职责 如果你学习编程的目的只是玩玩,那随意,想怎么学怎么学。...

不要再到处使用 === 了

我们知道现在的开发人员都使用 === 来代替 ==,为什么呢?我在网上看到的大多数教程都认为,要预测 JavaScript 强制转换是如何工作这太复杂了,因此建议总是使用===。这些都...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

立即提问
相关内容推荐