This commit is contained in:
Jay 2017-08-17 18:19:16 +08:00
parent 18ae807a5b
commit 37ac5f399a

View File

@ -1,6 +1,10 @@
package xyz.mtfos.btdemo
import android.Manifest
import android.annotation.SuppressLint
import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.widget.Button
@ -31,6 +35,15 @@ class MainActivity : Activity() {
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 {
val txt: String = intxt.text.toString()
ble?.sendLongData(txt.toByteArray())
@ -44,6 +57,10 @@ class MainActivity : Activity() {
}
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}
override fun onStop() {
super.onStop()
disconnect()
@ -84,5 +101,7 @@ class MainActivity : Activity() {
}
disconnectBtn.isEnabled = false
connectBtn.isEnabled = true
btn.isEnabled = false
isInit = false
}
}