當前位置:首頁 » 安卓系統 » androidble配對

androidble配對

發布時間: 2022-08-02 17:49:16

Ⅰ 為什麼安卓6.0需要開啟定位才能搜索藍牙ble設備

電腦藍牙和手機藍牙一般用來相互之間傳文件。是無法查看對方的盤符里的文件的。
電腦發送文件給手機:
右擊「我的藍牙「圖標,選發送文件。
找到想要發送的手機,然後點擊該手機。
選擇要傳送的文件。
第一次連接,手機端需要按提示輸入一個配對碼。對方選擇接收即可。
手機給電腦發送文件:
1.選擇手機上的文件,點擊「分享」,以藍牙方式發送。
2.選擇匹配的電腦即發送,等待電腦選擇接收即可。

Ⅱ android藍牙配對 如何自動配對設置PIN碼

Android對於音頻設備是自動輸入0000的pin碼的,參照$frameworks/base/core/java/android/server/BluetoothEventLoop.java 的onRequestPinCode()你若是在app里編寫代碼,可以在收到ACTION_PAIRING_REQUEST的時候,直接調用BluetoothDevice.setpin()reference $package/apps/Settings/src/android/settings/bluetooth/BluetoothPairingDialog.java 的onPair();

Ⅲ Android藍牙BLE連接如何設置串口,數據格式為含1位起始位、7位數據位、1位奇偶校驗位和1位終止位

字元長度=1+7+1+2=11 b/字元
數據速率R1=11×100=1100 b/s
有效數據速率R=7×100=700 b/s
選B

Ⅳ Android 藍牙ble配對 發送PIN碼無效問題

android藍牙自動配對連接的具體代碼如下:
1. 獲取藍牙適配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 為null,說明android手機沒有藍牙模塊。
2. 判斷藍牙模塊是否開啟,blueadapter.isEnabled() true表示已經開啟,false表示藍牙並沒啟用。
3. 啟動配置藍牙可見模式,即進入可配對模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
4. 獲取藍牙適配器中已經配對的設備Set<BluetoothDevice> device=blueadapter.getBondedDevices();
當然,還需要在androidManifest.xml中聲明藍牙的許可權
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5.自動配對設置Pin值
static public boolean autoBond(Class btClass, BluetoothDevice device, String strPin)
throws Exception {
Method autoBondMethod = btClass.getMethod("setPin", new Class[] { byte[].class });
Boolean result = (Boolean) autoBondMethod
.invoke(device, new Object[] { strPin.getBytes() });
return result;
}
6.開始配對請求
static public boolean createBond(Class btClass, BluetoothDevice device) throws Exception {
Method createBondMethod = btClass.getMethod("createBond");
Boolean returnValue = (Boolean) createBondMethod.invoke(device);
return returnValue.booleanValue();
}

Ⅳ Android BLE為什麼首次連接藍牙設備比較慢

光講連接的話應該是不會出現這個問題的,你是不是做過保存連接的操作,所以第一次慢,以後快。

Ⅵ Android 手機可以通過 BLE 被掃描到嗎

本文介紹Android ble 藍牙4.0,也就是說API level >= 18,且支持藍牙4.0的手機才可以使用,如果手機系統版本API
level < 18,也是用不了藍牙4.0的哦。

首先發一下官方的demo,有興趣的可以過去看看:http://developer.android.com/guide/topics/connectivity/bluetooth-le.html。android系統4.3以上,手機支持藍牙4.0,具有搜索,配對,連接,發現服務及特徵值,斷開連接等功能,下載地址:http://download.csdn.net/detail/lqw770737185/8116019。

一、了解api及概念

1.1 BluetoothGatt

繼承BluetoothProfile,通過BluetoothGatt可以連接設備(connect),發現服務(discoverServices),並把相應地屬性返回到BluetoothGattCallback

1.2 BluetoothGattCharacteristic

相當於一個數據類型,它包括一個value和0~n個value的描述(BluetoothGattDescriptor)

1.3 BluetoothGattDescriptor

描述符,對Characteristic的描述,包括范圍、計量單位等

1.4 BluetoothGattService

服務,Characteristic的集合。

1.5 BluetoothProfile

一個通用的規范,按照這個規范來收發數據。

1.6 BluetoothManager

通過BluetoothManager來獲取BluetoothAdapter

BluetoothManager bluetoothManager = (BluetoothManager)
getSystemService(Context.BLUETOOTH_SERVICE);

1.7 BluetoothAdapter

一個Android系統只有一個BluetoothAdapter ,通過BluetoothManager 獲取

BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();

1.8 BluetoothGattCallback

已經連接上設備,對設備的某些操作後返回的結果。這里必須提醒下,已經連接上設備後的才可以返回,沒有返回的認真看看有沒有連接上設備。

private BluetoothGattCallback GattCallback = new BluetoothGattCallback()
{

// 這里有9個要實現的方法,看情況要實現那些,用到那些就實現那些

public void onConnectionStateChange(BluetoothGatt gatt, int status, int
newState){};

public void onCharacteristicWrite(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status){};

};

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);

BluetoothGatt gatt = device.connectGatt(this, false, mGattCallback);

1.8.1:notification對應onCharacteristicChanged;

gatt.setCharacteristicNotification(characteristic, true);

1.8.2:readCharacteristic對應onCharacteristicRead;

gatt.readCharacteristic(characteristic);

1.8.3: writeCharacteristic對應onCharacteristicWrite;

gatt.wirteCharacteristic(mCurrentcharacteristic);

1.8.4:連接藍牙或者斷開藍牙 對應 onConnectionStateChange;

1.8.5: readDescriptor對應onDescriptorRead;

1.8.6:writeDescriptor對應onDescriptorWrite;

gatt.writeDescriptor(descriptor);

1.8.7:readRemoteRssi對應onReadRemoteRssi;

gatt.readRemoteRssi()

1.8.8:executeReliableWrite對應onReliableWriteCompleted;

1.8.9:discoverServices對應onServicesDiscovered。

gatt.discoverServices()

1.9 BluetoothDevice

掃描後發現可連接的設備,獲取已經連接的設備

二、開啟藍牙許可權如果
android.hardware.bluetooth_le設置為false,可以安裝在不支持的設備上使用,判斷是否支持藍牙4.0用以下代碼就可以了

if
(!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
{

Toast.makeText(this, "設備不支持藍牙4.0", Toast.LENGTH_SHORT).show();

finish();

}

三、對藍牙的啟動關閉操作

1、利用系統默認開啟藍牙對話框

if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {

Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);

startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

}

2、後台打開藍牙,不做任何提示,這個也可以用來自定義打開藍牙對話框啦

mBluetoothAdapter.enable();

3、後台關閉藍牙

mBluetoothAdapter.disable();

四、掃描設備,連接設備,獲取設備信息 ,斷開連接設備,自行查看官方demo,還是看demo比較清晰啊

Ⅶ 安卓編程,藍牙連接怎麼做

Android 藍牙編程的基本步驟:

  1. 獲取藍牙適配器BluetoothAdapterblueadapter=BluetoothAdapter.getDefaultAdapter();

    如果BluetoothAdapter 為null,說明android手機沒有藍牙模塊。

  2. 判斷藍牙模塊是否開啟,blueadapter.isEnabled() true表示已經開啟,false表示藍牙並沒啟用。

  3. 啟動配置藍牙可見模式,即進入可配對模式Intentin=newIntent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);

    in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,200);

    startActivity(in); ,200就表示200秒。

  4. 獲取藍牙適配器中已經配對的設備Set<BluetoothDevice>device=blueadapter.getBondedDevices();

當然,還需要在androidManifest.xml中聲明藍牙的許可權

<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

接下來就是根據自己的需求對BluetoothAdapter的操作了。

Ⅷ android 藍牙BLE 多設備連接

一次只能連接一個外圍設備吧

熱點內容
phpecho換行 發布:2024-04-30 02:21:51 瀏覽:903
高中ftp 發布:2024-04-30 01:51:48 瀏覽:873
林秋楠手機的密碼是多少 發布:2024-04-30 01:46:31 瀏覽:276
python靜態類方法 發布:2024-04-30 01:30:28 瀏覽:462
zblogphpasp 發布:2024-04-30 01:27:35 瀏覽:137
宏程序自動編程軟體 發布:2024-04-30 01:15:01 瀏覽:417
vs添加編譯選項 發布:2024-04-30 01:06:10 瀏覽:614
編程紅碼 發布:2024-04-30 01:04:49 瀏覽:910
給數組賦值java 發布:2024-04-30 01:04:37 瀏覽:499
我的世界jave版如何開伺服器 發布:2024-04-30 01:02:34 瀏覽:902