├── .classpath
├── .gitattributes
├── .github
└── workflows
│ ├── stale.yml
│ └── sync_issues.yml
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── README.md
├── bin
├── AndroidManifest.xml
├── BLE_Example.apk
├── XadowBLE.apk
├── classes.dex
├── classes
│ └── com
│ │ └── example
│ │ └── seeedstudio
│ │ └── BLE
│ │ ├── BaseView.class
│ │ ├── BluetoothLeService$1.class
│ │ ├── BluetoothLeService$LocalBinder.class
│ │ ├── BluetoothLeService.class
│ │ ├── BuildConfig.class
│ │ ├── Control$1.class
│ │ ├── Control$2.class
│ │ ├── Control$3.class
│ │ ├── Control$4.class
│ │ ├── Control$5.class
│ │ ├── Control.class
│ │ ├── Device.class
│ │ ├── MainActivity$1$1.class
│ │ ├── MainActivity$1.class
│ │ ├── MainActivity$2$1.class
│ │ ├── MainActivity$2.class
│ │ ├── MainActivity$3.class
│ │ ├── MainActivity$4.class
│ │ ├── MainActivity.class
│ │ ├── R$attr.class
│ │ ├── R$dimen.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$layout.class
│ │ ├── R$menu.class
│ │ ├── R$string.class
│ │ ├── R$style.class
│ │ ├── R.class
│ │ ├── SampleGattAttributes.class
│ │ └── SearchDevicesView.class
├── dexedLibs
│ ├── android-support-v4-61fd59ca7a434d08f11d5fd05371e341.jar
│ └── android-support-v4-d4719140fd8633e23e4a32f81ae411ab.jar
├── jarlist.cache
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_launcher.png
│ │ └── drawable
│ │ ├── backgroud.png
│ │ ├── devicescan.png
│ │ ├── gplus_search_args.png
│ │ ├── gplus_search_bg.png
│ │ ├── gplus_search_bg1.png
│ │ ├── ic_launcher.png
│ │ ├── locus_round_click.png
│ │ ├── locus_round_click1.png
│ │ └── redbear.png
└── resources.ap_
├── gen
└── com
│ └── example
│ └── seeedstudio
│ └── BLE
│ ├── BuildConfig.java
│ └── R.java
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-ldpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── backgroud.png
│ ├── devicescan.png
│ ├── gplus_search_args.png
│ ├── gplus_search_bg.png
│ ├── gplus_search_bg1.png
│ ├── ic_launcher.png
│ ├── locus_round_click.png
│ ├── locus_round_click1.png
│ ├── red_button.xml
│ └── redbear.png
├── layout
│ ├── device_list.xml
│ ├── list_item.xml
│ ├── loading_process_dialog_anim.xml
│ ├── main.xml
│ └── second.xml
├── menu
│ └── bletest.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
├── values-w820dp
│ └── dimens.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── seeedstudio
└── BLE
├── BaseView.java
├── BluetoothLeService.java
├── Control.java
├── Device.java
├── MainActivity.java
├── SampleGattAttributes.java
└── SearchDevicesView.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: 'Close stale issues and PRs'
2 |
3 | on:
4 | workflow_dispatch:
5 | schedule:
6 | - cron: '0 4 * * *'
7 |
8 | jobs:
9 | stale:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - name: Checkout repository
14 | uses: actions/checkout@v4
15 |
16 | - name: Checkout script repository
17 | uses: actions/checkout@v4
18 | with:
19 | repository: Seeed-Studio/sync-github-all-issues
20 | path: ci
21 |
22 | - name: Run script
23 | run: ./ci/tools/stale.sh
24 | env:
25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26 |
--------------------------------------------------------------------------------
/.github/workflows/sync_issues.yml:
--------------------------------------------------------------------------------
1 | name: Automate Issue Management
2 |
3 | on:
4 | issues:
5 | types:
6 | - opened
7 | - edited
8 | - assigned
9 | - unassigned
10 | - labeled
11 | - unlabeled
12 | - reopened
13 |
14 | jobs:
15 | add_issue_to_project:
16 | runs-on: ubuntu-latest
17 | steps:
18 | - name: Add issue to GitHub Project
19 | uses: actions/add-to-project@v1.0.2
20 | with:
21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17
22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }}
23 | labeled: bug
24 | label-operator: NOT
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Windows image file caches
2 | Thumbs.db
3 | ehthumbs.db
4 |
5 | # Folder config file
6 | Desktop.ini
7 |
8 | # Recycle Bin used on file shares
9 | $RECYCLE.BIN/
10 |
11 | # Windows Installer files
12 | *.cab
13 | *.msi
14 | *.msm
15 | *.msp
16 |
17 | # =========================
18 | # Operating System Files
19 | # =========================
20 |
21 | # OSX
22 | # =========================
23 |
24 | .DS_Store
25 | .AppleDouble
26 | .LSOverride
27 |
28 | # Icon must end with two \r
29 | Icon
30 |
31 | # Thumbnails
32 | ._*
33 |
34 | # Files that might appear on external disk
35 | .Spotlight-V100
36 | .Trashes
37 |
38 | # Directories potentially created on remote AFP share
39 | .AppleDB
40 | .AppleDesktop
41 | Network Trash Folder
42 | Temporary Items
43 | .apdisk
44 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | BLE_Example
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## BLE Example
2 |
3 | ### Introduction
4 | 
5 | This android app is used to build communication with BLE Slave device. You can send/receive message with these devices, such as [Xadow BLE](http://www.seeedstudio.com/depot/Xadow-BLE-p-1727.html) or [Xadow BLE Slave](http://www.seeedstudio.com/depot/Xadow-BLE-Slave-p-1546.html). It will help you to increase the understanding of BLE.
6 | ### Usage
7 | ####1. Install the APK
8 |
9 | 1. Install the APK file(**BLE_Example.apk**) in bin/ folder, you need to make sure the android verison of your smart phone is higher than 4.3.
10 | 2. After successful install, click the ico of the APK, and you will see the UI as follow.
11 | 
12 |
13 |
14 |
15 | ####2. Scan for slave devices
16 |
17 | 1.click the **start** button in the center of UI, it will start to scan for BLE slave devices. just like follow:
18 | 
19 |
20 | 2. The scan period will be up to 8 seconds, when it finished, the scan result will be show in the following dialog:
21 | 
22 |
23 | 3. click the BLE device that you want to connect, then your mobilephone will try to connect the specified device automatically.
24 |
25 | ####3. Select specified UUID
26 | 1. If you can connect the ble slave device successfully, the UI will be as follow:
27 | 
28 | You will find that the UUID is null and you need to pick up one from the list of **Characteristics UUID List**
29 | 2. Here we choose the UUID:0000ffe1-0000-1000-8000-00805f9b34fb, and the UI turns to:
30 | 
31 |
32 | ####4. Send and recv data
33 | OK, the exciting moment has come! Input the command(data) to the textbox, and then click the Send button, the message will be send to the specified ble devices. and the recv textbox will show the message from the slave devices, just as follow. Have fun!
34 | 
35 | 
36 |
37 |
38 | ----
39 | This software is written by lawliet zou () for [Seeed Technology Inc.](http://www.seeed.cc) and is licensed under The GPL v2 License. Check License.txt for more information.
40 |
41 | Contributing to this software is warmly welcomed. You can do this basically by [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above for operating guide). Adding change log and your contact into file header is encouraged.
42 | Thanks for your contribution.
43 |
44 | Seeed is a hardware innovation platform for makers to grow inspirations into differentiating products. By working closely with technology providers of all scale, Seeed provides accessible technologies with quality, speed and supply chain knowledge. When prototypes are ready to iterate, Seeed helps productize 1 to 1,000 pcs using in-house engineering, supply chain management and agile manufacture forces. Seeed also team up with incubators, Chinese tech ecosystem, investors and distribution channels to portal Maker startups beyond.
45 |
46 | [](https://github.com/igrigorik/ga-beacon)
47 |
48 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
40 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/bin/BLE_Example.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/BLE_Example.apk
--------------------------------------------------------------------------------
/bin/XadowBLE.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/XadowBLE.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes.dex
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/BaseView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/BaseView.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService$LocalBinder.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService$LocalBinder.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/BluetoothLeService.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control$3.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control$4.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control$5.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control$5.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Control.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Control.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/Device.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/Device.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$1$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$1$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$2$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$2$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$3.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$3.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity$4.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity$4.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/MainActivity.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$attr.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$dimen.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$drawable.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$id.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$menu.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R$style.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/R.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/SampleGattAttributes.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/SampleGattAttributes.class
--------------------------------------------------------------------------------
/bin/classes/com/example/seeedstudio/BLE/SearchDevicesView.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/classes/com/example/seeedstudio/BLE/SearchDevicesView.class
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-61fd59ca7a434d08f11d5fd05371e341.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/dexedLibs/android-support-v4-61fd59ca7a434d08f11d5fd05371e341.jar
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-d4719140fd8633e23e4a32f81ae411ab.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/dexedLibs/android-support-v4-d4719140fd8633e23e4a32f81ae411ab.jar
--------------------------------------------------------------------------------
/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/backgroud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/backgroud.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/devicescan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/devicescan.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/gplus_search_args.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/gplus_search_args.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/gplus_search_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/gplus_search_bg.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/gplus_search_bg1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/gplus_search_bg1.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/locus_round_click.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/locus_round_click.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/locus_round_click1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/locus_round_click1.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable/redbear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/res/crunch/drawable/redbear.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/bin/resources.ap_
--------------------------------------------------------------------------------
/gen/com/example/seeedstudio/BLE/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.seeedstudio.BLE;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/gen/com/example/seeedstudio/BLE/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.seeedstudio.BLE;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class dimen {
14 | /** Default screen margins, per the Android Design guidelines.
15 |
16 | Example customization of dimensions originally defined in res/values/dimens.xml
17 | (such as screen margins) for screens with more than 820dp of available width. This
18 | would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
19 |
20 | */
21 | public static final int activity_horizontal_margin=0x7f040000;
22 | public static final int activity_vertical_margin=0x7f040001;
23 | }
24 | public static final class drawable {
25 | public static final int backgroud=0x7f020000;
26 | public static final int devicescan=0x7f020001;
27 | public static final int gplus_search_args=0x7f020002;
28 | public static final int gplus_search_bg=0x7f020003;
29 | public static final int gplus_search_bg1=0x7f020004;
30 | public static final int ic_launcher=0x7f020005;
31 | public static final int locus_round_click=0x7f020006;
32 | public static final int locus_round_click1=0x7f020007;
33 | public static final int red_button=0x7f020008;
34 | public static final int redbear=0x7f020009;
35 | }
36 | public static final class id {
37 | public static final int action_settings=0x7f08000f;
38 | public static final int btn_send=0x7f08000b;
39 | public static final int deviceAddr=0x7f080002;
40 | public static final int deviceName=0x7f080001;
41 | public static final int et_tx=0x7f08000c;
42 | public static final int expandableListView1=0x7f08000e;
43 | public static final int listView=0x7f080000;
44 | public static final int pageloading=0x7f080003;
45 | public static final int search_device_view=0x7f080004;
46 | public static final int tv_connstatus=0x7f080007;
47 | public static final int tv_deviceaddr=0x7f080006;
48 | public static final int tv_devicename=0x7f080005;
49 | public static final int tv_rssi=0x7f080008;
50 | public static final int tv_rssi_value=0x7f080009;
51 | public static final int tv_rx=0x7f08000d;
52 | public static final int tv_targetuuid=0x7f08000a;
53 | }
54 | public static final class layout {
55 | public static final int device_list=0x7f030000;
56 | public static final int list_item=0x7f030001;
57 | public static final int loading_process_dialog_anim=0x7f030002;
58 | public static final int main=0x7f030003;
59 | public static final int second=0x7f030004;
60 | }
61 | public static final class menu {
62 | public static final int bletest=0x7f070000;
63 | }
64 | public static final class string {
65 | public static final int action_settings=0x7f050001;
66 | public static final int app_name=0x7f050000;
67 | public static final int searching=0x7f050002;
68 | }
69 | public static final class style {
70 | /**
71 | Base application theme, dependent on API level. This theme is replaced
72 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
73 |
74 |
75 | Theme customizations available in newer API levels can go in
76 | res/values-vXX/styles.xml, while customizations related to
77 | backward-compatibility can go here.
78 |
79 |
80 | Base application theme for API 11+. This theme completely replaces
81 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
82 |
83 | API 11 theme customizations can go here.
84 |
85 | Base application theme for API 14+. This theme completely replaces
86 | AppBaseTheme from BOTH res/values/styles.xml and
87 | res/values-v11/styles.xml on API 14+ devices.
88 |
89 | API 14 theme customizations can go here.
90 | */
91 | public static final int AppBaseTheme=0x7f060000;
92 | /** Application theme.
93 | All customizations that are NOT specific to a particular API-level can go here.
94 | */
95 | public static final int AppTheme=0x7f060001;
96 | public static final int button_text=0x7f060002;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-20
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/backgroud.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/backgroud.png
--------------------------------------------------------------------------------
/res/drawable/devicescan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/devicescan.png
--------------------------------------------------------------------------------
/res/drawable/gplus_search_args.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/gplus_search_args.png
--------------------------------------------------------------------------------
/res/drawable/gplus_search_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/gplus_search_bg.png
--------------------------------------------------------------------------------
/res/drawable/gplus_search_bg1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/gplus_search_bg1.png
--------------------------------------------------------------------------------
/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/locus_round_click.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/locus_round_click.png
--------------------------------------------------------------------------------
/res/drawable/locus_round_click1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/locus_round_click1.png
--------------------------------------------------------------------------------
/res/drawable/red_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
6 |
7 |
8 |
10 |
11 |
14 |
15 |
17 |
18 |
23 |
24 |
25 |
26 | -
27 |
28 |
32 |
33 |
36 |
37 |
39 |
40 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/res/drawable/redbear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Seeed-Studio/BLE_Example/c69e13f9d01cf79079627562f6d748c32e9c1198/res/drawable/redbear.png
--------------------------------------------------------------------------------
/res/layout/device_list.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
--------------------------------------------------------------------------------
/res/layout/loading_process_dialog_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
17 |
18 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/res/layout/second.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
11 |
12 |
17 |
24 |
31 |
32 |
33 |
34 |
39 |
46 |
53 |
54 |
55 |
56 |
61 |
68 |
69 |
76 |
77 |
78 |
83 |
91 |
92 |
99 |
100 |
101 |
106 |
113 |
114 |
122 |
123 |
124 |
125 |
131 |
137 |
143 |
144 |
145 |
151 |
158 |
165 |
166 |
167 |
173 |
179 |
180 |
181 |
187 |
188 |
189 |
--------------------------------------------------------------------------------
/res/menu/bletest.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | BLE
5 | Settings
6 | Searching....
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
34 |
35 |
--------------------------------------------------------------------------------
/src/com/example/seeedstudio/BLE/BaseView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.seeedstudio.BLE;
18 |
19 | import android.content.Context;
20 | import android.graphics.Bitmap;
21 | import android.graphics.BitmapFactory;
22 | import android.graphics.Canvas;
23 | import android.util.AttributeSet;
24 | import android.widget.RelativeLayout;
25 |
26 | public class BaseView extends RelativeLayout{
27 |
28 | public Context context;
29 |
30 | public BaseView(Context context) {
31 | super(context);
32 | this.context = context;
33 | }
34 |
35 | public BaseView(Context context, AttributeSet attrs) {
36 | super(context, attrs);
37 | this.context = context;
38 | }
39 |
40 | public BaseView(Context context, AttributeSet attrs, int defStyle) {
41 | super(context, attrs, defStyle);
42 | this.context = context;
43 | }
44 |
45 |
46 | @Override
47 | protected void onDraw(Canvas canvas) {
48 | super.onDraw(canvas);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/com/example/seeedstudio/BLE/BluetoothLeService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.seeedstudio.BLE;
18 | import java.util.List;
19 | import java.util.UUID;
20 |
21 | import android.app.Service;
22 | //import android.app.Activity;
23 | import android.content.Context;
24 | import android.content.Intent;
25 | import android.os.Binder;
26 | import android.os.IBinder;
27 | import android.util.Log;
28 | import android.bluetooth.BluetoothDevice;
29 | import android.bluetooth.BluetoothGattCallback;
30 | import android.bluetooth.BluetoothGattCharacteristic;
31 | import android.bluetooth.BluetoothGattDescriptor;
32 | //import android.bluetooth.BluetoothGattDescriptor;
33 | import android.bluetooth.BluetoothGattService;
34 | import android.bluetooth.BluetoothManager;
35 | import android.bluetooth.BluetoothAdapter;
36 | import android.bluetooth.BluetoothGatt;
37 | import android.bluetooth.BluetoothProfile;
38 |
39 |
40 | public class BluetoothLeService extends Service{
41 | private final static String TAG = BluetoothLeService.class.getSimpleName();
42 |
43 | private BluetoothManager mBluetoothManager;
44 | private BluetoothAdapter mBluetoothAdapter;
45 | private BluetoothGatt mBluetoothGatt;
46 | private String mBluetoothDeviceAddress;
47 | private int mConnectionState = STATE_DISCONNECTED;
48 |
49 | //private final int REQUEST_ENABLE_BT = 1;
50 | private static final int STATE_DISCONNECTED = 0;
51 | private static final int STATE_CONNECTING = 1;
52 | private static final int STATE_CONNECTED = 2;
53 |
54 | public final static String ACTION_GATT_CONNECTED =
55 | "com.example.bluetooth.le.ACTION_GATT_CONNECTED";
56 | public final static String ACTION_GATT_DISCONNECTED =
57 | "com.example.bluetooth.le.ACTION_GATT_DISCONNECTED";
58 | public final static String ACTION_GATT_SERVICES_DISCOVERED =
59 | "com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED";
60 | public final static String ACTION_GATT_RSSI =
61 | "com.example.bluetooth.le.ACTION_GATT_RSSI";
62 | public final static String ACTION_DATA_AVAILABLE =
63 | "com.example.bluetooth.le.ACTION_DATA_AVAILABLE";
64 | public final static String EXTRA_DATA =
65 | "com.example.bluetooth.le.EXTRA_DATA";
66 |
67 | public final static UUID UUID_BLE_TX = UUID
68 | .fromString(SampleGattAttributes.BLE_TX);
69 | public final static UUID UUID_BLE_RX = UUID
70 | .fromString(SampleGattAttributes.BLE_RX);
71 | public final static UUID UUID_BLE_SERVICE = UUID
72 | .fromString(SampleGattAttributes.BLE_SERVICE);
73 |
74 |
75 |
76 | private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback(){
77 | @Override
78 | public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState){
79 | String intentAction;
80 | if (newState == BluetoothProfile.STATE_CONNECTED) {
81 | intentAction = ACTION_GATT_CONNECTED;
82 | mConnectionState = STATE_CONNECTED;
83 | broadcastUpdate(intentAction);
84 | Log.i(TAG, "Connected to GATT server.");
85 | // Attempts to discover services after successful connection.
86 | Log.i(TAG, "Attempting to start service discovery:" +
87 | mBluetoothGatt.discoverServices());
88 |
89 | } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
90 | intentAction = ACTION_GATT_DISCONNECTED;
91 | mConnectionState = STATE_DISCONNECTED;
92 | Log.i(TAG, "Disconnected from GATT server.");
93 | broadcastUpdate(intentAction);
94 | }
95 | }
96 |
97 | public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
98 | Log.d(TAG, "onReadRemoteRssi");
99 | if (status == BluetoothGatt.GATT_SUCCESS) {
100 | broadcastUpdate(ACTION_GATT_RSSI, rssi);
101 | } else {
102 | Log.w(TAG, "onReadRemoteRssi received: " + status);
103 | }
104 | };
105 |
106 | @Override
107 | public void onServicesDiscovered(BluetoothGatt gatt, int status) {
108 | if (status == BluetoothGatt.GATT_SUCCESS) {
109 | broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
110 | } else {
111 | Log.w(TAG, "onServicesDiscovered received: " + status);
112 | }
113 | }
114 |
115 | @Override
116 | public void onCharacteristicRead(BluetoothGatt gatt,
117 | BluetoothGattCharacteristic characteristic,
118 | int status) {
119 | if (status == BluetoothGatt.GATT_SUCCESS) {
120 | broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
121 | //Log.d(TAG, "read " + new String(characteristic.getValue()));
122 | }else{
123 | Log.w(TAG, "onCharacteristicRead: " + status);
124 | }
125 | }
126 |
127 | @Override
128 | public void onCharacteristicChanged(BluetoothGatt gatt,
129 | BluetoothGattCharacteristic characteristic) {
130 | broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
131 | }
132 | };
133 |
134 | private void broadcastUpdate(final String action) {
135 | final Intent intent = new Intent(action);
136 | sendBroadcast(intent);
137 | }
138 |
139 | private void broadcastUpdate(final String action, int rssi) {
140 | Log.d(TAG, "broadcastUpdate - rssi");
141 | final Intent intent = new Intent(action);
142 | intent.putExtra(EXTRA_DATA, String.valueOf(rssi));
143 | sendBroadcast(intent);
144 | }
145 |
146 | private void broadcastUpdate(final String action, final BluetoothGattCharacteristic characteristic) {
147 | final Intent intent = new Intent(action);
148 |
149 | if (UUID_BLE_RX.equals(characteristic.getUuid())) {
150 | Log.d(TAG,"write data to extra data");
151 | final byte[] rx = characteristic.getValue();
152 | Log.d(TAG, "rx[0] = " + rx[0]);
153 | intent.putExtra(EXTRA_DATA, rx);
154 | }
155 | sendBroadcast(intent);
156 | }
157 |
158 | public class LocalBinder extends Binder {
159 | BluetoothLeService getService() {
160 | return BluetoothLeService.this;
161 | }
162 | }
163 |
164 | @Override
165 | public IBinder onBind(Intent intent) {
166 | return mBinder;
167 | }
168 |
169 | @Override
170 | public boolean onUnbind(Intent intent) {
171 | // After using a given device, you should make sure that BluetoothGatt.close() is called
172 | // such that resources are cleaned up properly. In this particular example, close() is
173 | // invoked when the UI is disconnected from the Service.
174 | close();
175 | return super.onUnbind(intent);
176 | }
177 |
178 | private final IBinder mBinder = new LocalBinder();
179 |
180 |
181 | /**
182 | * Initializes a reference to the local Bluetooth adapter.
183 | *
184 | * @return Return true if the initialization is successful.
185 | */
186 | public boolean initialize(){
187 | if(mBluetoothManager == null){
188 | mBluetoothManager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
189 | if(mBluetoothManager == null){
190 | Log.e(TAG, "Unable to initialize BluetoothManager.");
191 | return false;
192 | }
193 | }
194 | mBluetoothAdapter = mBluetoothManager.getAdapter();
195 | if(mBluetoothAdapter == null){
196 | Log.e(TAG, "Unable to get Bluetooth Adapter.");
197 | return false;
198 | }
199 |
200 | return true;
201 | }
202 |
203 | /**
204 | * Connects to the GATT server hosted on the Bluetooth LE device.
205 | *
206 | * @param address The device address of the destination device.
207 | *
208 | * @return Return true if the connection is initiated successfully. The connection result
209 | * is reported asynchronously through the
210 | * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}
211 | * callback.
212 | */
213 | public boolean connect(final String address){
214 | if (mBluetoothAdapter == null || address == null) {
215 | Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
216 | return false;
217 | }
218 | // Previously connected device. Try to reconnect.
219 | if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
220 | && mBluetoothGatt != null) {
221 | Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
222 | if (mBluetoothGatt.connect()) {
223 | mConnectionState = STATE_CONNECTING;
224 | return true;
225 | } else {
226 | final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
227 | mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
228 | mBluetoothDeviceAddress = address;
229 | Log.d(TAG, "Connection failed");
230 | return false;
231 | }
232 | }
233 |
234 | final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
235 | if (device == null) {
236 | Log.w(TAG, "Device not found. Unable to connect.");
237 | return false;
238 | }
239 | // We want to directly connect to the device, so we are setting the autoConnect
240 | // parameter to false.
241 | mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
242 | Log.d(TAG, "Trying to create a new connection.");
243 | mBluetoothDeviceAddress = address;
244 | mConnectionState = STATE_CONNECTING;
245 | return true;
246 | }
247 |
248 | /**
249 | * Disconnects an existing connection or cancel a pending connection. The disconnection result
250 | * is reported asynchronously through the
251 | * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}
252 | * callback.
253 | */
254 | public void disconnect() {
255 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
256 | Log.w(TAG, "BluetoothAdapter not initialized");
257 | return;
258 | }
259 | mBluetoothGatt.disconnect();
260 | }
261 |
262 | /**
263 | * After using a given BLE device, the app must call this method to ensure resources are
264 | * released properly.
265 | */
266 | public void close() {
267 | if (mBluetoothGatt == null) {
268 | return;
269 | }
270 | mBluetoothGatt.close();
271 | mBluetoothGatt = null;
272 | }
273 |
274 | /**
275 | * Request a read on a given {@code BluetoothGattCharacteristic}. The read result is reported
276 | * asynchronously through the {@code BluetoothGattCallback#onCharacteristicRead(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattCharacteristic, int)}
277 | * callback.
278 | *
279 | * @param characteristic The characteristic to read from.
280 | */
281 | public void readCharacteristic(BluetoothGattCharacteristic characteristic) {
282 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
283 | Log.w(TAG, "BluetoothAdapter not initialized");
284 | return;
285 | }
286 | mBluetoothGatt.readCharacteristic(characteristic);
287 | }
288 |
289 |
290 | public void readRssi() {
291 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
292 | Log.w(TAG, "BluetoothAdapter not initialized");
293 | return;
294 | }
295 |
296 | mBluetoothGatt.readRemoteRssi();
297 | }
298 |
299 | /**
300 | * Write to a given char
301 | * @param characteristic The characteristic to write to
302 | */
303 | public void writeCharacteristic(BluetoothGattCharacteristic characteristic) {
304 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
305 | Log.w(TAG, "BluetoothAdapter not initialized");
306 | return;
307 | }
308 |
309 | mBluetoothGatt.writeCharacteristic(characteristic);
310 | }
311 |
312 | /**
313 | * Enables or disables notification on a give characteristic.
314 | *
315 | * @param characteristic Characteristic to act on.
316 | * @param enabled If true, enable notification. False otherwise.
317 | */
318 | public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
319 | boolean enabled) {
320 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
321 | Log.w(TAG, "BluetoothAdapter not initialized");
322 | return;
323 | }
324 | mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
325 |
326 | // This is specific to Heart Rate Measurement.
327 | //if (UUID_BLE_RX.equals(characteristic.getUuid())) {
328 | // BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
329 | //UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
330 | //descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
331 | //mBluetoothGatt.writeDescriptor(descriptor);
332 | //}
333 | }
334 |
335 |
336 | public void getCharacteristicDescriptor(BluetoothGattDescriptor descriptor)
337 | {
338 | if (mBluetoothAdapter == null || mBluetoothGatt == null) {
339 | Log.w(TAG, "BluetoothAdapter not initialized");
340 | return;
341 | }
342 |
343 | mBluetoothGatt.readDescriptor(descriptor);
344 | }
345 |
346 |
347 | /**
348 | * Retrieves a list of supported GATT services on the connected device. This should be
349 | * invoked only after {@code BluetoothGatt#discoverServices()} completes successfully.
350 | *
351 | * @return A {@code List} of supported services.
352 | */
353 |
354 | public List getSupportedGattServices() {
355 | if (mBluetoothGatt == null) {
356 | Log.d(TAG, "getSupportedGattService: mBluetoothGatt == null");
357 | return null;
358 | }
359 |
360 | return mBluetoothGatt.getServices();
361 | }
362 |
363 |
364 |
365 | }
--------------------------------------------------------------------------------
/src/com/example/seeedstudio/BLE/Control.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.seeedstudio.BLE;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.List;
22 |
23 | import com.example.seeedstudio.BLE.R;
24 |
25 | import android.app.Activity;
26 | import android.bluetooth.BluetoothGattCharacteristic;
27 | import android.bluetooth.BluetoothGattDescriptor;
28 | import android.bluetooth.BluetoothGattService;
29 | import android.content.BroadcastReceiver;
30 | import android.content.ComponentName;
31 | import android.content.Context;
32 | import android.content.Intent;
33 | import android.content.IntentFilter;
34 | import android.content.ServiceConnection;
35 | import android.os.Bundle;
36 | import android.os.IBinder;
37 | import android.util.Log;
38 | import android.view.MenuItem;
39 | import android.view.View;
40 | import android.view.View.OnClickListener;
41 | import android.widget.Button;
42 | import android.widget.EditText;
43 | import android.widget.ExpandableListView;
44 | import android.widget.SimpleExpandableListAdapter;
45 | import android.widget.TextView;
46 | import android.widget.Toast;
47 |
48 | public class Control extends Activity {
49 | private final static String TAG = Control.class.getSimpleName();
50 | private final static String UUID_KEY_DATA = "0000ffe1-0000-1000-8000-00805f9b34fb";
51 | BluetoothGattCharacteristic characteristicTXRX = null;
52 | public static final String EXTRAS_DEVICE = "EXTRAS_DEVICE";
53 | private String mDeviceName = null;
54 | private String mDeviceAddress = null;
55 | private final String LIST_NAME = "NAME";
56 | private final String LIST_UUID = "UUID";
57 | private boolean mConnected = false;
58 | private String rssi_value;
59 | private BluetoothGattCharacteristic mNotifyCharacteristic;
60 | private BluetoothLeService mBluetoothLeService = null;
61 | private BluetoothGattCharacteristic target_character = null;
62 | private ArrayList> mGattCharacteristics =
63 | new ArrayList>();
64 |
65 | private Button btn_write;
66 | private TextView tv_deviceName,tv_deviceAddr,tv_connstatus,tv_currentRSSI,tv_targetUUID,tv_rx;
67 | private EditText et_send;
68 | ExpandableListView lv;
69 |
70 |
71 |
72 | @Override
73 | protected void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 | setContentView(R.layout.second);
76 |
77 | btn_write = (Button) findViewById(R.id.btn_send);
78 | tv_deviceName = (TextView) findViewById(R.id.tv_devicename);
79 | tv_deviceAddr = (TextView) findViewById(R.id.tv_deviceaddr);
80 | tv_connstatus = (TextView) findViewById(R.id.tv_connstatus);
81 | tv_currentRSSI = (TextView) findViewById(R.id.tv_rssi_value);
82 | tv_currentRSSI.setText("null");
83 | tv_targetUUID = (TextView) findViewById(R.id.tv_targetuuid);
84 | tv_targetUUID.setText("null");
85 | tv_rx = (TextView) findViewById(R.id.tv_rx);
86 | et_send = (EditText) findViewById(R.id.et_tx);
87 | lv=(ExpandableListView)this.findViewById(R.id.expandableListView1);
88 | lv.setOnChildClickListener(servicesListClickListner);
89 |
90 | Intent intent = getIntent();
91 | Log.d(TAG, "Control onCreate");
92 |
93 | mDeviceAddress = intent.getStringExtra(Device.EXTRA_DEVICE_ADDRESS);
94 | mDeviceName = intent.getStringExtra(Device.EXTRA_DEVICE_NAME);
95 | Log.d(TAG, "mDeviceAddress = " + mDeviceAddress);
96 | Log.d(TAG, "mDeviceName = " + mDeviceName);
97 | tv_deviceName.setText(mDeviceName);
98 | tv_deviceAddr.setText(mDeviceAddress);
99 |
100 | getActionBar().setTitle(mDeviceName);
101 | getActionBar().setDisplayHomeAsUpEnabled(true);
102 |
103 | Log.d(TAG, "start BluetoothLE Service");
104 |
105 | Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
106 | bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
107 |
108 |
109 | btn_write.setOnClickListener(new OnClickListener() {
110 | @Override
111 | public void onClick(View v) {
112 | if(target_character != null){
113 | String cmd = et_send.getText().toString();
114 | Log.d(TAG,"send cmd:"+cmd);
115 | if(cmd != null){
116 | byte b = 0x00;
117 | byte[] tmp = cmd.getBytes();
118 | byte[] tx = new byte[tmp.length + 1];
119 | tx[0] = b;
120 | for (int i = 1; i < tmp.length + 1; i++) {
121 | tx[i] = tmp[i - 1];
122 | }
123 | target_character.setValue(tx);
124 | mBluetoothLeService.writeCharacteristic(target_character);
125 | } else {
126 | Toast.makeText(Control.this, "Please type your command.", Toast.LENGTH_SHORT).show();
127 | }
128 | }else{
129 | Toast.makeText(Control.this, "Please select a UUID.", Toast.LENGTH_SHORT).show();
130 | }
131 | et_send.setText(null);
132 | }
133 | });
134 | }
135 |
136 |
137 | private final ServiceConnection mServiceConnection = new ServiceConnection() {
138 |
139 | @Override
140 |
141 | public void onServiceConnected(ComponentName componentName,
142 | IBinder service) {
143 | Log.d(TAG, "start service Connection");
144 | mBluetoothLeService = ((BluetoothLeService.LocalBinder) service).getService();
145 | if (!mBluetoothLeService.initialize()) {
146 | Log.e(TAG, "Unable to initialize Bluetooth");
147 | finish();
148 | }
149 | // Automatically connects to the device upon successful start-up
150 | // initialization.
151 | Log.d(TAG, "mDeviceAddress = " + mDeviceAddress);
152 | boolean status = mBluetoothLeService.connect(mDeviceAddress);
153 | if(status == true){
154 | Log.d(TAG, "connection OK");
155 | }else{
156 | Log.d(TAG, "Connection failed");
157 | }
158 | }
159 |
160 | @Override
161 | public void onServiceDisconnected(ComponentName componentName) {
162 | Log.d(TAG, "end Service Connection");
163 | mBluetoothLeService = null;
164 | }
165 | };
166 |
167 | private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
168 | @Override
169 | public void onReceive(Context context, Intent intent) {
170 | Log.d(TAG, "enter BroadcastReceiver");
171 | final String action = intent.getAction();
172 | Log.d(TAG, "action = " + action);
173 | if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
174 | mConnected = true;
175 | updateConnectionState(mConnected);
176 | System.out.println("BroadcastReceiver :"+"device connected");
177 |
178 | } else if(BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
179 | mConnected = false;
180 | updateConnectionState(mConnected);
181 | } else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
182 | Log.d(TAG, "services discovered!!!");
183 | //getGattService(mBluetoothLeService.getSupportedGattServices());
184 | displayGattServices(mBluetoothLeService.getSupportedGattServices());
185 | startReadRssi();
186 | //startReadInformation();
187 | } else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
188 | Log.d(TAG, "receive data");
189 | byte[] value = intent.getByteArrayExtra(BluetoothLeService.EXTRA_DATA);
190 | if(value != null){
191 | displayData(value);
192 | }else{
193 | Log.d(TAG, "value = null");
194 | }
195 | } else if (BluetoothLeService.ACTION_GATT_RSSI.equals(action)) {
196 | Log.d(TAG, "BroadCast + RSSI");
197 | rssi_value = intent.getStringExtra(BluetoothLeService.EXTRA_DATA);
198 | rssi_value += "dB";
199 | Log.d(TAG, "rssi_value = " + rssi_value);
200 | updateRSSI(rssi_value);
201 | }
202 | }
203 |
204 | private void updateRSSI(String value) {
205 | // TODO Auto-generated method stub
206 | if(value != null){
207 | tv_currentRSSI.setText(value);
208 | }
209 | }
210 |
211 | private void updateConnectionState(boolean status) {
212 | // TODO Auto-generated method stub
213 | if(status){
214 | tv_connstatus.setText("connected");
215 | }else{
216 | tv_connstatus.setText("unconnected");
217 | }
218 | }
219 | };
220 |
221 | private void startReadRssi() {
222 | new Thread() {
223 | public void run() {
224 |
225 | while (true) {
226 | try {
227 | mBluetoothLeService.readRssi();
228 | sleep(2000);
229 | } catch (InterruptedException e) {
230 | e.printStackTrace();
231 | }
232 | }
233 | };
234 | }.start();
235 | }
236 |
237 |
238 | private void onCharacteristicsRead(String uuidStr, byte[] value) {
239 | Log.i(TAG, "onCharacteristicsRead: " + uuidStr);
240 | if (value != null && value.length > 0) {
241 | final StringBuilder stringBuilder = new StringBuilder(value.length);
242 | for (byte byteChar : value) {
243 | stringBuilder.append(String.format("%02X ", byteChar));
244 | }
245 | displayData(stringBuilder.toString());
246 | }
247 | }
248 |
249 | private void displayData(String data) {
250 | if (data != null) {
251 | tv_rx.setText(data);
252 | }
253 | }
254 |
255 | @Override
256 | protected void onResume() {
257 | super.onResume();
258 | registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
259 | }
260 |
261 | @Override
262 | public boolean onOptionsItemSelected(MenuItem item) {
263 | if (item.getItemId() == android.R.id.home) {
264 | mBluetoothLeService.disconnect();
265 | mBluetoothLeService.close();
266 |
267 | System.exit(0);
268 | }
269 |
270 | return super.onOptionsItemSelected(item);
271 | }
272 |
273 | @Override
274 | protected void onStop() {
275 | super.onStop();
276 |
277 | unregisterReceiver(mGattUpdateReceiver);
278 | }
279 |
280 | @Override
281 | protected void onDestroy() {
282 | super.onDestroy();
283 |
284 | mBluetoothLeService.disconnect();
285 | mBluetoothLeService.close();
286 |
287 | System.exit(0);
288 | }
289 |
290 | private void displayData(byte[] data) {
291 | if (data != null) {
292 | String dataArray = new String(data);
293 | Log.d(TAG, "data = " + dataArray);
294 | tv_rx.setText(dataArray);
295 | }
296 |
297 | }
298 |
299 | private static IntentFilter makeGattUpdateIntentFilter() {
300 | final IntentFilter intentFilter = new IntentFilter();
301 |
302 | intentFilter.addAction(BluetoothLeService.ACTION_GATT_CONNECTED);
303 | intentFilter.addAction(BluetoothLeService.ACTION_GATT_DISCONNECTED);
304 | intentFilter.addAction(BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED);
305 | intentFilter.addAction(BluetoothLeService.ACTION_DATA_AVAILABLE);
306 | intentFilter.addAction(BluetoothLeService.ACTION_GATT_RSSI);
307 | return intentFilter;
308 | }
309 |
310 | private void displayGattServices(List gattServices) {
311 |
312 | if (gattServices == null) return;
313 | String uuid = null;
314 | String unknownServiceString = "unknown_service";
315 | String unknownCharaString = "unknown_characteristic";
316 |
317 | ArrayList> gattServiceData = new ArrayList>();
318 |
319 | ArrayList>> gattCharacteristicData
320 | = new ArrayList>>();
321 |
322 | mGattCharacteristics = new ArrayList>();
323 |
324 | // Loops through available GATT Services.
325 | for (BluetoothGattService gattService : gattServices) {
326 | HashMap currentServiceData = new HashMap();
327 | uuid = gattService.getUuid().toString();
328 |
329 | currentServiceData.put(
330 | LIST_NAME, SampleGattAttributes.lookup(uuid, unknownServiceString));
331 | currentServiceData.put(LIST_UUID, uuid);
332 | gattServiceData.add(currentServiceData);
333 |
334 | System.out.println("Service uuid:"+uuid);
335 |
336 | ArrayList> gattCharacteristicGroupData =
337 | new ArrayList>();
338 |
339 | List gattCharacteristics =
340 | gattService.getCharacteristics();
341 |
342 | ArrayList charas =
343 | new ArrayList();
344 |
345 | // Loops through available Characteristics.
346 | for (BluetoothGattCharacteristic gattCharacteristic : gattCharacteristics) {
347 | charas.add(gattCharacteristic);
348 | HashMap currentCharaData = new HashMap();
349 | uuid = gattCharacteristic.getUuid().toString();
350 |
351 | currentCharaData.put(
352 | LIST_NAME, SampleGattAttributes.lookup(uuid, unknownCharaString));
353 | currentCharaData.put(LIST_UUID, uuid);
354 |
355 | System.out.println("GattCharacteristic uuid:"+uuid);
356 | System.out.println("--GattCharacteristic Properties:"+gattCharacteristic.getProperties());
357 | //mBluetoothLeService.readCharacteristic(gattCharacteristic);
358 | // System.out.println("--GattCharacteristic value2:"+gattCharacteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0));
359 | //BluetoothGattDescriptor Descriptor=gattCharacteristic.getDescriptor(gattCharacteristic.getUuid());
360 | //System.out.println("--GattCharacteristic Descriptor:"+Descriptor.toString());
361 |
362 | List descriptors= gattCharacteristic.getDescriptors();
363 | for(BluetoothGattDescriptor descriptor:descriptors){
364 | System.out.println("---descriptor UUID:"+descriptor.getUuid());
365 | mBluetoothLeService.getCharacteristicDescriptor(descriptor);
366 | }
367 | gattCharacteristicGroupData.add(currentCharaData);
368 | }
369 | mGattCharacteristics.add(charas);
370 | gattCharacteristicData.add(gattCharacteristicGroupData);
371 | }
372 | SimpleExpandableListAdapter gattServiceAdapter = new SimpleExpandableListAdapter(
373 | this,
374 | gattServiceData,
375 | android.R.layout.simple_expandable_list_item_2,
376 | new String[] {LIST_NAME, LIST_UUID},
377 | new int[] { android.R.id.text1, android.R.id.text2 },
378 | gattCharacteristicData,
379 | android.R.layout.simple_expandable_list_item_2,
380 | new String[] {LIST_NAME, LIST_UUID},
381 | new int[] { android.R.id.text1, android.R.id.text2 }
382 | );
383 | lv.setAdapter(gattServiceAdapter);
384 | }
385 |
386 | private final ExpandableListView.OnChildClickListener servicesListClickListner =
387 | new ExpandableListView.OnChildClickListener() {
388 | @Override
389 | public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
390 | int childPosition, long id) {
391 | if (mGattCharacteristics != null) {
392 | final BluetoothGattCharacteristic characteristic =
393 | mGattCharacteristics.get(groupPosition).get(childPosition);
394 |
395 | target_character = characteristic;
396 | tv_targetUUID.setText(characteristic.getUuid().toString());
397 |
398 | final int charaProp = characteristic.getProperties();
399 | if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
400 | // If there is an active notification on a characteristic, clear
401 | // it first so it doesn't update the data field on the user interface.
402 | if (mNotifyCharacteristic != null) {
403 | mBluetoothLeService.setCharacteristicNotification(
404 | mNotifyCharacteristic, false);
405 | mNotifyCharacteristic = null;
406 | }
407 | mBluetoothLeService.readCharacteristic(characteristic);
408 | }
409 | if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
410 | mNotifyCharacteristic = characteristic;
411 | mBluetoothLeService.setCharacteristicNotification(
412 | characteristic, true);
413 | }
414 | return true;
415 | }
416 | return false;
417 | }
418 | };
419 | }
420 |
--------------------------------------------------------------------------------
/src/com/example/seeedstudio/BLE/Device.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.seeedstudio.BLE;
18 |
19 | import java.util.ArrayList;
20 | import java.util.HashMap;
21 | import java.util.List;
22 | import java.util.Map;
23 |
24 | import com.example.seeedstudio.BLE.R;
25 | import android.app.Activity;
26 | import android.bluetooth.BluetoothDevice;
27 | import android.content.Intent;
28 | import android.os.Bundle;
29 | import android.view.View;
30 | import android.widget.AdapterView;
31 | import android.widget.AdapterView.OnItemClickListener;
32 | import android.widget.ListView;
33 | import android.widget.SimpleAdapter;
34 |
35 | public class Device extends Activity implements OnItemClickListener {
36 |
37 | private ArrayList devices;
38 | private List