├── .gitignore
├── .idea
├── caches
│ └── build_file_checksums.ser
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── qaplug_profiles.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── np
│ │ └── lekotlin
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── np
│ │ │ └── lekotlin
│ │ │ ├── MainActivity.kt
│ │ │ └── blemodule
│ │ │ ├── BLEConnectionManager.kt
│ │ │ ├── BLEConstants.kt
│ │ │ ├── BLEDeviceManager.kt
│ │ │ ├── BLEService.kt
│ │ │ ├── BleDeviceData.kt
│ │ │ └── OnDeviceScanListener.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── np
│ └── lekotlin
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/libraries
5 | /.idea/modules.xml
6 | /.idea/workspace.xml
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nithinjith/LEKotlin-Android/51ee7edad3f24cfed30e9334715ca158e1ea29f3/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.idea/qaplug_profiles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LEKotlin-Android
2 | This is Kotlin Application of Bluetooth Low Energy Device Integration. The module explains a working sample of the BLE device. The App will initially scan the surrounding devices, the scan result will pass to the Activity. The user can select a device from the scan result. If the scanning process over, the user can connect the device. After connecting the device, the application will check the Available Service in the device and Available characteristics in the Device. If the Service and characteristics are identified then the user can start read-write and notify process.
3 |
4 | The Application creates a server-client model.
5 |
6 | A bounded service is used to read, write and notify data from the BLE
7 |
8 | The data will be updated to the Activity through a Broadcast receiver
9 |
10 | Two singleton class is used in the BLE module
11 |
12 | One for Scan Handling and the Other one for reading, writing and find services.
13 |
14 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | defaultConfig {
10 | applicationId "com.np.lekotlin"
11 | minSdkVersion 21
12 | targetSdkVersion 28
13 | versionCode 1
14 | versionName "1.0"
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | buildToolsVersion '28.0.3'
24 | productFlavors {
25 | }
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(include: ['*.jar'], dir: 'libs')
30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
31 | implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
32 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
36 | }
37 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/np/lekotlin/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.np.lekotlin
2 |
3 | import androidx.test.InstrumentationRegistry
4 | import androidx.test.runner.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getTargetContext()
22 | assertEquals("com.np.lekotlin", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/np/lekotlin/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.np.lekotlin
2 |
3 | import android.Manifest
4 | import android.app.AlertDialog
5 | import android.bluetooth.BluetoothAdapter
6 | import android.content.BroadcastReceiver
7 | import android.content.Context
8 | import android.content.Intent
9 | import android.content.IntentFilter
10 | import android.content.pm.PackageManager
11 | import android.os.Build
12 | import androidx.appcompat.app.AppCompatActivity
13 | import android.os.Bundle
14 | import android.os.Handler
15 | import androidx.core.app.ActivityCompat
16 | import androidx.core.content.ContextCompat
17 | import android.util.Log
18 | import android.view.View
19 | import android.widget.Button
20 | import android.widget.TextView
21 | import android.widget.Toast
22 | import com.np.lekotlin.blemodule.*
23 |
24 | class MainActivity : AppCompatActivity(), OnDeviceScanListener, View.OnClickListener {
25 |
26 | private lateinit var mBtnReadConnectionChar: Button
27 | private lateinit var mBtnReadBatteryLevel: Button
28 | private lateinit var mBtnReadEmergency: Button
29 | private lateinit var mBtnWriteEmergency: Button
30 | private lateinit var mBtnWriteConnection: Button
31 | private lateinit var mBtnWriteBatteryLevel: Button
32 | private lateinit var mTvResult: TextView
33 |
34 | private var mDeviceAddress: String = ""
35 |
36 |
37 | override fun onScanCompleted(deviceDataList: BleDeviceData) {
38 |
39 | //Initiate a dialog Fragment from here and ask the user to select his device
40 | // If the application already know the Mac address, we can simply call connect device
41 |
42 | mDeviceAddress = deviceDataList.mDeviceAddress
43 | BLEConnectionManager.connect(deviceDataList.mDeviceAddress)
44 |
45 | }
46 |
47 | private val REQUEST_LOCATION_PERMISSION = 2018
48 | private val TAG = "MainActivity"
49 | private val REQUEST_ENABLE_BT = 1000
50 | override fun onCreate(savedInstanceState: Bundle?) {
51 | super.onCreate(savedInstanceState)
52 | setContentView(R.layout.activity_main)
53 |
54 | mBtnReadConnectionChar = findViewById