This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val discoverableIntent =Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE) | |
| discoverableIntent | |
| .putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,0/*set a duration, 0 is not recommended*/) | |
| startActivity(discoverableIntent) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun scanLeDevice(enable: Boolean) { | |
| when (enable) { | |
| true -> { | |
| // Stops scanning after a pre-defined scan period. | |
| Handler().postDelayed({ | |
| mScanning = false | |
| bluetoothAdapter?.bluetoothLeScanner?.stopScan(mLeScanCallback) | |
| }, 5000) | |
| mScanning = true | |
| bluetoothAdapter?.bluetoothLeScanner?.startScan(mLeScanCallback) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun allowLocationDetectionPermissions() { | |
| if (ContextCompat.checkSelfPermission(this@MainActivity, Manifest.permission.ACCESS_FINE_LOCATION) | |
| == PackageManager.PERMISSION_DENIED) { | |
| ActivityCompat.requestPermissions(this@MainActivity, | |
| arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), FINE_LOCATION_PERMISSION_REQUEST) | |
| } | |
| } | |
| override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) { | |
| when (requestCode) { |