日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

【Android 应用开发】Android之Bluetooth编程

發布時間:2025/6/17 Android 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Android 应用开发】Android之Bluetooth编程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android Bluetopth 編程大牛文章

http://my.oschina.net/u/994235/blog?catalog=313604













ViewGroup 相關資料 :?

http://www.incoding.org/admin/archives/199.html

http://bbs.csdn.net/topics/370144745

http://www.linuxidc.com/Linux/2013-01/78109.htm

http://blog.csdn.net/arui319/article/details/5868466

http://www.2cto.com/kf/201109/104633.html

http://www.cnblogs.com/slider/archive/2011/11/24/2262161.html




藍牙開發指南 :?

http://wenku.baidu.com/view/b41c1b09bb68a98271fefae1.html


藍牙編程 :

http://wenku.baidu.com/link?url=QT1NMnkqNk3Emm_CueUyqtawXyQ2-CNIu5Es6xgtbj2KLUe5Cu5mXo2xDbvnBRLuvH044uiF2Vhcwjz4o8uCdkYYiUV3R71Id4GIdEQsPLe






http://blog.csdn.net/qinjuning/article/details/7726093??BluetoothAdapter類簡介

http://www.cnblogs.com/over140/archive/2010/12/21/1912460.html

Android 中文API (69) —— BluetoothAdapter[藍牙]

http://www.wuphone.com/579.html?BluetoothAdapter藍牙

http://www.cnblogs.com/over140/archive/2010/12/21/1912482.html??

BluetoothDevice[藍牙]


http://blog.csdn.net/forlong401/article/details/8536209???

android藍牙開發——基本概念



http://blog.csdn.net/hellogv/article/details/6042091?十三篇之探秘藍牙隱藏API

http://www.cnblogs.com/wanqieddy/archive/2013/05/24/3096312.html?隱藏api介紹

http://www.eoeandroid.com/thread-18993-1-1.html?_dsign=d70c243d?Android藍牙開發淺談

http://blog.csdn.net/myarrow/article/details/8143717?安卓設備待機廣播


http://www.cnblogs.com/fbsk/archive/2011/10/10/2205316.html??

Android開機自啟動程序


http://wenku.baidu.com/view/6baf53eaaeaad1f346933f85.html?

http://android.toolib.net/reference/android/bluetooth/BluetoothServerSocket.html

BlueToothServerSocket API解析


http://jinguo.iteye.com/blog/687357

http://android.toolib.net/reference/android/bluetooth/BluetoothSocket.html

BlueToothSocket API解析


http://blog.csdn.net/xiluoduyu/article/details/8515286

http://www.linuxidc.com/Linux/2012-09/69586.htm

藍牙模塊開發


使用代碼打開藍牙

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
System.out.println(" 打開藍牙 ");
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);


http://my.oschina.net/billowworld/blog/62975? ?

如何實現android藍牙開發 自動配對連接,并不彈出提示框


http://www.eoeandroid.com/thread-249231-1-1.html?藍牙取消配對方法

http://blog.csdn.net/zzy916853616/article/details/6597746??android開發之藍牙初步 掃描已配對藍牙、更改藍牙可見性、搜索外部藍牙設備


Android中通過靜態注冊的屏幕開啟和屏幕關閉的BroadCastReceiver為什么捕捉不到廣播?

  • kandee

    -1 票

  • 1

android開發中使用AndroidManiFest.xml靜態注冊的BroadCastReceiver沒有作用是什么原因?

使用靜態注冊,Debug運行,就是沒進到onReceive()方法那里去。我用真機調試的。

但是使用動態注冊,又可以捕捉到。我想問,這個系統廣播可不可以靜態注冊?如果可以為什么會捕捉不到呢?


在Android 的廣播機制中,動態注冊的優先級是要高于靜態注冊優先級的,你是否在調試時2個都注冊了,所以出現你的這種情況;當用來注冊動態廣播接收器的activity被關閉時,這個動態接收器也就是就失效了,靜態注冊的廣播接收器只要有你注冊的廣播出現就能接收到廣播。


對于這兩個action:

android.intent.action.SCREEN_OFF
android.intent.action.SCREEN_ON

在AndroidManifest.xml中注冊是不可以的。

這有點不同于其他的action,你只有在Service中通過動態注冊去監聽這個事件。

這個問題我的理解是google故意這么做的,有兩點考慮:
1.提高監聽screen_on screen_off門檻
這兩個事件是android的基本事件,如果唄大多數程序監聽,會大大的拖慢整個系統,所以android也應該不鼓勵我們在后臺監聽這兩個事件。

2.有讓我們在service后臺監聽
這也是提供了一個解決問題,強調和service共存亡,不會一直在后臺無限情運行。

總之應該是為了保證系統的穩定和安全才采取這樣的措施。
希望對你有幫助。



藍牙配對密碼設置

先是寫個
<receiver android:name=".broadcast.PairingRequest">
? ? ? ? ? ? ? ?? ?<intent-filter>
? ? ? ? ? ? ? ?? ???<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />?
? ? ? ? ? ? ? ?? ???<action android:name="android.bluetooth.device.action.PAIRING_CANCEL" />?
? ? ? ? ? ? ? ?? ?</intent-filter>
? ? ? ? ? ? ? ? </receiver>

然后是你的
public class PairingRequest extends BroadcastReceiver{
??@Override
??public void onReceive(Context context, Intent intent){
? ? if (intent.getAction().equals("ACTION_PAIRING_REQUEST")) {
? ? ? ? ? ? BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
? ? ? ? ? ? byte[] pinBytes = BluetoothDevice.convertPinToBytes("1234");
? ? ? ? ? ? device.setPin(pinBytes);
? ? }
??}
}

其中的藍牙BluetoothDevice這個類要用源碼里的替換下

藍牙設備是怎么連接的?

最前提的條件是有藍牙的MAC地址; String macAddress;

根據藍牙的MAC地址 , 可以獲得藍牙設備BluetoothDevice對象 , BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macAddress);

將藍牙設備對象傳入服務中的connect方法中;

將設備連接放在線程中完成 , 創建一個設備連接的線程 , 啟動這個線程.



BluetoothAdapter資料 :?

關于權限資料

 android.permission.BLUETOOTH?允許程序連接到已配對的藍牙設備(Allows applications to connect to paired bluetooth devices)
  android.permission.BLUETOOTH_ADMIN?允許程序發現和配對藍牙設備(Allows applications to discover and pair bluetooth devices)


android藍牙開發——權限

為了在應用程序中使用藍牙功能,我們至少需要聲明兩方面的權限:BLUETOOTH和BLUETOOTH_ADMIN。

你必須請求BLUETOOTH權限才能夠實現藍牙通信,例如請求一個連接、接受一個連接和傳輸數據。

你必須請求BLUETOOTH_ADMIN權限,才能夠初始化device discovery或者管理藍牙設置(Bluetooth settings)。大多數應用程序必須具有這個權限才能夠發現本地藍牙設備,這個權限保護的其他能力(除了發現本地設備)不應該被使用,除非你的應用程序是在用戶請求的時候能夠修改藍牙設置的管理者。

注意:如果你想要使用BLUETOOTH_ADMIN權限,那么你首先必須有BLUETOOTH權限。

你需要在應用程序的manifest文件中聲明程序的藍牙權限。例如:

[xhtml]?view plaincopy
  • <manifest?...?>??
  • ??<uses-permission?android:name="android.permission.BLUETOOTH"?/>??
  • ??...??
  • </manifest>??
  • 關于聲明應用程序權限的信息,請看<uses-permission>參考。
















    總結

    以上是生活随笔為你收集整理的【Android 应用开发】Android之Bluetooth编程的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。