update
This commit is contained in:
parent
18ae807a5b
commit
37ac5f399a
@ -1,6 +1,10 @@
|
|||||||
package xyz.mtfos.btdemo
|
package xyz.mtfos.btdemo
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
@ -31,6 +35,15 @@ class MainActivity : Activity() {
|
|||||||
|
|
||||||
ble = BLECls(this@MainActivity)
|
ble = BLECls(this@MainActivity)
|
||||||
|
|
||||||
|
var permissionCheck: Int = 0
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
permissionCheck += this@MainActivity.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||||
|
permissionCheck += this@MainActivity.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
|
if (permissionCheck != 0) {
|
||||||
|
requestPermissions(arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION), 111)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
btn.setOnClickListener {
|
btn.setOnClickListener {
|
||||||
val txt: String = intxt.text.toString()
|
val txt: String = intxt.text.toString()
|
||||||
ble?.sendLongData(txt.toByteArray())
|
ble?.sendLongData(txt.toByteArray())
|
||||||
@ -44,12 +57,16 @@ class MainActivity : Activity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
disconnect()
|
disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun scanConnect(){
|
fun scanConnect() {
|
||||||
if (ble?.init()!!) {
|
if (ble?.init()!!) {
|
||||||
isInit = true
|
isInit = true
|
||||||
ble?.startScan()
|
ble?.startScan()
|
||||||
@ -84,5 +101,7 @@ class MainActivity : Activity() {
|
|||||||
}
|
}
|
||||||
disconnectBtn.isEnabled = false
|
disconnectBtn.isEnabled = false
|
||||||
connectBtn.isEnabled = true
|
connectBtn.isEnabled = true
|
||||||
|
btn.isEnabled = false
|
||||||
|
isInit = false
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user