litle fix for more correctly permision processing
This commit is contained in:
17
.idea/deploymentTargetDropDown.xml
generated
17
.idea/deploymentTargetDropDown.xml
generated
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="deploymentTargetDropDown">
|
||||
<runningDeviceTargetSelectedWithDropDown>
|
||||
<Target>
|
||||
<type value="RUNNING_DEVICE_TARGET" />
|
||||
<deviceKey>
|
||||
<Key>
|
||||
<type value="SERIAL_NUMBER" />
|
||||
<value value="3d29e5a6" />
|
||||
</Key>
|
||||
</deviceKey>
|
||||
</Target>
|
||||
</runningDeviceTargetSelectedWithDropDown>
|
||||
<timeTargetWasSelectedWithDropDown value="2023-06-24T21:15:01.924740400Z" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,12 +4,20 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
signingConfigs {
|
||||
debug {
|
||||
storeFile file('/home/gogacoder/AndroidStudioProjects/keychain/key.jks')
|
||||
storePassword '123456'
|
||||
keyPassword '123456'
|
||||
keyAlias 'key0'
|
||||
}
|
||||
}
|
||||
namespace 'com.listerk.helible'
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.listerk.helible"
|
||||
minSdk 31
|
||||
minSdk 30
|
||||
targetSdk 34
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
20
app/debug/output-metadata.json
Normal file
20
app/debug/output-metadata.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "com.listerk.helible",
|
||||
"variantName": "debug",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1,
|
||||
"versionName": "1.0",
|
||||
"outputFile": "app-debug.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
||||
@@ -2,10 +2,18 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Legacy permissions (API 30 and below) -->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
|
||||
<!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" android:maxSdkVersion="30"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="30"/>-->
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
|
||||
<uses-feature android:name="android.hardware.bluetooth" />
|
||||
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
|
||||
<uses-feature android:name="android.hardware.bluetooth_le" />
|
||||
|
||||
<application
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package com.listerk.helible
|
||||
|
||||
object AppState {
|
||||
lateinit var bleDevice: BleDevice;
|
||||
lateinit var bleDevice: BleDevice
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.listerk.helible
|
||||
|
||||
import android.util.Log
|
||||
//import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
//import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
//import org.w3c.dom.Text
|
||||
|
||||
class BleDeviceAdapter(private val devices: List<BleDevice>, private val gotoControlBtn: Button) :
|
||||
RecyclerView.Adapter<BleDeviceAdapter.BleDeviceViewHolder>() {
|
||||
@@ -41,9 +42,9 @@ class BleDeviceAdapter(private val devices: List<BleDevice>, private val gotoCon
|
||||
}
|
||||
|
||||
class BleDeviceViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
val cardView = itemView.rootView
|
||||
val nameView = itemView.findViewById<TextView>(R.id.deviceName)
|
||||
val addressView = itemView.findViewById<TextView>(R.id.deviceAddress)
|
||||
val rssiView = itemView.findViewById<ImageView>(R.id.deviceRssi)
|
||||
val cardView: View = itemView.rootView
|
||||
val nameView: TextView = itemView.findViewById(R.id.deviceName)
|
||||
val addressView: TextView = itemView.findViewById(R.id.deviceAddress)
|
||||
val rssiView: ImageView = itemView.findViewById(R.id.deviceRssi)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ class ControlActivity : AppCompatActivity() {
|
||||
sliderR1.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
sliderR1Value = progress
|
||||
val val_text = getString(R.string.r_slider_text, 1, progress)
|
||||
sliderR1ValueText.text = val_text
|
||||
sliderR1ValueText.text = getString(R.string.r_slider_text, 1, progress)
|
||||
}
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {}
|
||||
@@ -38,8 +37,7 @@ class ControlActivity : AppCompatActivity() {
|
||||
sliderR2.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
sliderR2Value = progress
|
||||
val val_text = getString(R.string.r_slider_text, 2, progress)
|
||||
sliderR2ValueText.text = val_text
|
||||
sliderR2ValueText.text = getString(R.string.r_slider_text, 2, progress)
|
||||
}
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {}
|
||||
@@ -48,8 +46,7 @@ class ControlActivity : AppCompatActivity() {
|
||||
sliderR3.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
sliderR3Value = progress
|
||||
val val_text = getString(R.string.r_slider_text, 3, progress)
|
||||
sliderR3ValueText.text = val_text
|
||||
sliderR3ValueText.text = getString(R.string.r_slider_text, 3, progress)
|
||||
}
|
||||
override fun onStartTrackingTouch(p0: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(p0: SeekBar?) {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.listerk.helible
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.bluetooth.BluetoothAdapter
|
||||
import android.bluetooth.BluetoothManager
|
||||
import android.bluetooth.le.BluetoothLeScanner
|
||||
@@ -13,16 +14,17 @@ import android.graphics.drawable.Animatable
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
//import android.os.Handler
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.RequiresApi
|
||||
//import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private val bluetoothAdapter: BluetoothAdapter by lazy {
|
||||
val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||
@@ -31,7 +33,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private val bleScanner: BluetoothLeScanner by lazy {
|
||||
bluetoothAdapter.bluetoothLeScanner
|
||||
}
|
||||
|
||||
private val requiredPermissions: MutableSet<String> = mutableSetOf(Manifest.permission.BLUETOOTH_SCAN)
|
||||
private val foundDevices = mutableListOf<BleDevice>()
|
||||
|
||||
private val leScanCallback: ScanCallback = object : ScanCallback() {
|
||||
@@ -39,6 +41,7 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onScanResult(callbackType, result)
|
||||
val bleDevicesView = findViewById<RecyclerView>(R.id.bleDevicesView)
|
||||
val loader = findViewById<ImageView>(R.id.bleDevicesLoader)
|
||||
|
||||
if (result.device.name.isNullOrBlank()) {
|
||||
return
|
||||
}
|
||||
@@ -48,7 +51,7 @@ class MainActivity : AppCompatActivity() {
|
||||
loader.visibility = View.GONE
|
||||
}
|
||||
|
||||
var deviceIndex = foundDevices.indexOfFirst { it.address == result.device.address }
|
||||
var deviceIndex: Int = foundDevices.indexOfFirst { it.address == result.device.address }
|
||||
if (deviceIndex < 0) {
|
||||
deviceIndex = foundDevices.size
|
||||
foundDevices.add(BleDevice(result.device.name, result.device.address, result.rssi))
|
||||
@@ -76,23 +79,62 @@ class MainActivity : AppCompatActivity() {
|
||||
bleDevicesView.layoutManager = LinearLayoutManager(this)
|
||||
bleDevicesView.adapter = BleDeviceAdapter(foundDevices, gotoControlButton)
|
||||
bleDevicesView.itemAnimator = null
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this@MainActivity, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
Log.e("StartActivity", "We have denied permissions")
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||
{
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.BLUETOOTH_CONNECT), 2)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/*if(Build.VERSION.SDK_INT < 31) {
|
||||
requiredPermissions.add(android.Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
requiredPermissions.add(android.Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
requiredPermissions.add(android.Manifest.permission.ACCESS_BACKGROUND_LOCATION)
|
||||
}
|
||||
requestPermissions()*/
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT), 1)
|
||||
} else {
|
||||
/*if (!hasNecessaryPermissions()) {
|
||||
requestPermissions()
|
||||
} else {*/
|
||||
bleScanner.startScan(leScanCallback)
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT), 1)
|
||||
} else {
|
||||
/*if (!hasNecessaryPermissions()) {
|
||||
requestPermissions()
|
||||
} else {*/
|
||||
bleScanner.stopScan(leScanCallback)
|
||||
//}
|
||||
}
|
||||
|
||||
private fun hasNecessaryPermissions(): Boolean
|
||||
{
|
||||
for (it in requiredPermissions) {
|
||||
if (ActivityCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED) {
|
||||
Log.i("ScanActivity", "Permission isn't allowed: $it")
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
private fun requestPermissions()
|
||||
{
|
||||
Log.i("ScanActivity", "Trying to request permissions: $requiredPermissions")
|
||||
ActivityCompat.requestPermissions(this@MainActivity, requiredPermissions.toTypedArray(), 1)
|
||||
if(!hasNecessaryPermissions())
|
||||
{
|
||||
Log.e("ScanActivity", "Failed to get all permissions")
|
||||
} else {
|
||||
Log.i("ScanActivity", "App got permissions: $requiredPermissions")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,11 @@
|
||||
android:id="@+id/bleDevicesView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/devicesTitle"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="12dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/devicesTitle"
|
||||
tools:listitem="@layout/item_ble_device" />
|
||||
|
||||
<ImageView
|
||||
@@ -33,9 +34,10 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/loader"
|
||||
app:layout_constraintTop_toBottomOf="@id/bleDevicesView"
|
||||
android:visibility="invisible"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/bleDevicesView" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/gotoControlButton"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id 'com.android.application' version '8.0.2' apply false
|
||||
id 'com.android.library' version '8.0.2' apply false
|
||||
id 'com.android.application' version '8.1.0' apply false
|
||||
id 'com.android.library' version '8.1.0' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
|
||||
}
|
||||
Reference in New Issue
Block a user