當前位置:首頁 » 安卓系統 » android藍牙40

android藍牙40

發布時間: 2022-05-30 17:09:50

『壹』 android藍牙4.0一連多個設備

『貳』 android如何使用藍牙4.0控制多個藍牙設備

這個貌似不行,我感覺對外設進行通訊首先需要建立連接,而你只能連接一個外設

『叄』 android 4.0 藍牙開發 怎麼入手

本文介紹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

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

二、開啟藍牙許可權

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
如果 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中藍牙2.0和4.0的區別

最主要的區別就是藍牙2.0的傳輸速度沒有藍牙4.0快。以下為藍牙各版本的說明。

1.1 為最早期版本,傳輸率約在748~810kb/s,因是早期設計,容易受到同頻率之產品所干擾下影響通訊質量。
藍牙1.2標准
1.2 同樣是只有 748~810kb/s 的傳輸率,但在加上了(改善 Software)抗干擾跳頻功能。
藍牙2.0標准
2.0 是 1.2 的改良提升版,傳輸率約在 1.8M/s~2.1M/s,開始支持雙工模式——即一面作語音通訊,同時亦可以傳輸檔案/高質素圖片,2.0 版本當然也支持 Stereo 運作。
應用最為廣泛的是Bluetooth 2.0+EDR標准,該標准在2004年已經推出,支持Bluetooth 2.0+EDR標準的產品也於2006年大量出現。
雖然Bluetooth 2.0+EDR標准在技術上作了大量的改進,但從1.X標准延續下來的配置流程復雜和設備功耗較大的問題依然存在。
藍牙2.1標准
2007年8月2日,藍牙技術聯盟今天正式批准了藍牙2.1版規范,即「藍牙2.1+EDR」,可供未來的設備自由使用。和2.0版本同時代產品,目前仍然占據藍牙市場較大份額,相對2.0版本主要是提高了待機時間2倍以上,技術標准沒有根本性變化。
藍牙3.0標准
2009年4月21日,藍牙技術聯盟(Bluetooth SIG)正式頒布了新一代標准規范"Bluetooth Core Specification Version 3.0 High Speed"(藍牙核心規范3.0版 ),藍牙3.0的核心是"Generic Alternate MAC/PHY"(AMP),這是一種全新的交替射頻技術,允許藍牙協議棧針對任一任務動態地選擇正確射頻。
藍牙3.0的數據傳輸率提高到了大約24Mbps(即可在需要的時候調用802.11 WI-FI用於實現高速數據傳輸)。在傳輸速度上,藍牙3.0是藍牙2.0的八倍,可以輕松用於錄像機至高清電視、PC至PMP、UMPC至列印機之間的資料傳輸,但是需要雙方都達到此標准才能實現功能。
藍牙4.0標准
藍牙4.0規范於2010年7月7日正式發布,新版本的最大意義在於低功耗,同時加強不同OEM廠商之間的設備兼容性,並且降低延遲,理論最高傳輸速度依然為24Mbps(即3MB/s),有效覆蓋范圍擴大到100米(之前的版本為10米)。該標准晶元被大量的手機、平板所採用,如蘋果The New iPad平板電腦,以及蘋果iPhone 5、魅族MX4、HTC One X等手機上帶有藍牙4.0功能。
藍牙4.1標准
藍牙4.1於2013年12月6日發布,與LTE無線電信號之間如果同時傳輸數據,那麼藍牙4.1可以自動協調兩者的傳輸信息,理論上可以減少 其它信號對藍牙4.1的干擾。改進是提升了連接速度並且更加智能化,比如減少了設備之間重新連接的時間,意味著用戶如果走出了藍牙4.1的信號范圍並且斷開連接的時間不算很長,當用戶再次回到信號范圍中之後設備將自動連接,反應時間要比藍牙4.0更短。最後一個改進之處是提高傳輸效率,如果用戶連接的設備 非常多,比如連接了多部可穿戴設備,彼此之間的信息都能即時發送到接接收設備上。
除此之外,藍牙4.1也為開發人員增加了更多的靈活性,這個改變對普通用戶沒有很大影響,但是對於軟體開發者來說是很重要的,因為為了應對逐漸興起的可穿戴設備,那麼藍牙必須能夠支持同時連接多部設備。
目前支持該標準的手機還比較少,三星GALAXY Note4則是其中具有代表性的一款。
藍牙4.2標准
2014年12月4日,最新的藍牙4.2標准頒布,改善了數據傳輸速度和隱私保護程度,並接入了該設備將可直接通過IPv6和6LoWPAN接入互聯網。在新的標准下藍牙信號想要連接或者追蹤用戶設備必須經過用戶許可,否則藍牙信號將無法連接和追蹤用戶設備。
速度方面變得更加快速,兩部藍牙設備之間的數據傳輸速度提高了2.5倍,因為藍牙智能(Bluetooth Smart)數據包的容量提高,其可容納的數據量相當於此前的10倍左右。藍牙的版本自然是越高級越好,考慮到傳輸距離和功耗的問題,最新的藍牙4.1是優選,但是目前市場上藍牙4.1的產品並不多,而主流的藍牙4.0產品性價比更高,至於藍牙3.0、2.1及以下的版本已經失去選購的價值。

『伍』 什麼是android 藍牙

andriod是智能手機的操作系統,藍牙就是我們手機上用的無線數據傳輸工具,它的意思就是安卓系統手機的藍牙

『陸』 android 藍牙 開發問題

public boolean setName(String name)
Set the friendly Bluetooth name of the local Bluetoth adapter.
This name is visible to remote Bluetooth devices.
Valid Bluetooth names are a maximum of 248 UTF-8 characters, however many
remote devices can only display the first 40 characters, and some may be limited
to just 20.

文檔中不是有說明嗎!
最大有效值是用utf-8編碼的248個字元,然而有些藍牙設備最多能顯示40個字元,....20char。

『柒』 android藍牙4.0接收數據長度

事實上,我們在實際連接操作中(android + ble),不同的ble設備和不同的android設備連接過程都有不同的表現。但一般來說,連接6~7個是沒有問題的

『捌』 android藍牙4.0怎麼設置藍牙寫許可權

基本步驟:
獲取藍牙適配器BluetoothAdapter blueadapter=BluetoothAdapter.getDefaultAdapter();
如果BluetoothAdapter 為null,說明android手機沒有藍牙模塊。
判斷藍牙模塊是否開啟,blueadapter.isEnabled() true表示已經開啟,false表示藍牙並沒啟用。
啟動配置藍牙可見模式,即進入可配對模式Intent in=new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
in.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 200);
startActivity(in); ,200就表示200秒。
獲取藍牙適配器中已經配對的設備Set<BluetoothDevice> device=blueadapter.getBondedDevices();
還需要在androidManifest.xml中聲明藍牙的許可權
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
接下來就是根據自己的需求對BluetoothAdapter 的操作了。

『玖』 安卓手機的藍牙4.0和蘋果的藍牙4.0一樣嗎

一樣,藍牙4.0隻是模塊升級,現在的很多android 4.0一下的手機無法與藍牙4.0設備通信,android4.2版本會去除linux原先的bluez藍牙協議棧,用博通公司的bluedroid協議棧,估計這個android的release 可以支持藍牙4.0.。iphone4s以上的蘋果手機,都可以支持藍牙4.0

『拾』 android 怎麼連接藍牙設備

先展示代碼結構
步驟閱讀
2
連接藍牙類
類名:MainActivity(有點偷懶,沒有起表意的類名。)
步驟閱讀
3
要聲明的控制項和變數等
步驟閱讀
4
在onCreate聲明控制項
步驟閱讀
5
ToogleButton設置開關狀態
聲明一個組件願意接收
IntentFilter intent = new IntentFilter();
步驟閱讀
6
BroadcastReceiver廣播接收器
步驟閱讀
步驟閱讀
7
listview點擊事件
OnItemClickListener

OnClickListener
步驟閱讀
步驟閱讀
8
藍牙連接
步驟閱讀
9
退出消耗頁面是的onDestroy()
步驟閱讀
10
布局結構圖
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.bluetooth_connection.MainActivity" >
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal" >
<Button android:id="@+id/btnSearch" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="搜索" android:layout_weight="1" />
<Button android:id="@+id/btnExit" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="退出" android:layout_weight="1" />
<Button android:id="@+id/btnDis" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="開啟藍牙" android:layout_weight="1" /> </LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical" >
<ToggleButton android:id="@+id/tbtnSwitch" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:textOff="關閉藍牙" android:textOn="開啟藍牙" /> </LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.3" android:orientation="vertical" >
<ListView android:id="@+id/lvDevices" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f1f1f1" android:cacheColorHint="#ff333333" android:fadingEdge="none" android:scrollbars="none" > </ListView> </LinearLayout> </LinearLayout>
</RelativeLayout>

步驟閱讀
11
界面效果

步驟閱讀

12
例子如下

熱點內容
cryptopythonrsa 發布:2025-08-21 03:36:29 瀏覽:673
androidmandroidn 發布:2025-08-21 03:31:50 瀏覽:210
為什麼不能把安卓桌面app設為默認 發布:2025-08-21 03:22:31 瀏覽:442
愛奇藝會員密碼哪裡設置 發布:2025-08-21 03:11:57 瀏覽:262
電信電話密碼是什麼 發布:2025-08-21 03:08:14 瀏覽:446
sqlserver自動收縮 發布:2025-08-21 03:07:28 瀏覽:685
微信伺服器開哪個地址 發布:2025-08-21 03:06:12 瀏覽:652
diy源碼 發布:2025-08-21 02:42:36 瀏覽:480
信息存儲與信息檢索 發布:2025-08-21 02:22:32 瀏覽:122
android非同步數據載入數據 發布:2025-08-21 02:09:33 瀏覽:245