From cd063f2308c6ad2fa46607dd55b7c553aa4ad40a Mon Sep 17 00:00:00 2001 From: Gideon Okuro Date: Thu, 1 Feb 2024 22:31:47 +0300 Subject: [PATCH] actions: bluetooth permission newer way (fixes #1832) (#1833) Co-authored-by: dogi --- app/src/main/AndroidManifest.xml | 2 ++ .../remote/bases/BaseBluetoothChatService.kt | 9 ++++----- .../remote/bases/PermissionActivity.kt | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1cf651e57..799457c8b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,6 +4,8 @@ + + diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/BaseBluetoothChatService.kt b/app/src/main/kotlin/io/treehouses/remote/bases/BaseBluetoothChatService.kt index e951200a6..d6c661e40 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/BaseBluetoothChatService.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/BaseBluetoothChatService.kt @@ -2,6 +2,7 @@ package io.treehouses.remote.bases import android.app.Notification import android.app.PendingIntent +import android.app.PendingIntent.FLAG_IMMUTABLE import android.app.Service import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice @@ -55,8 +56,6 @@ open class BaseBluetoothChatService @JvmOverloads constructor(handler: Handler? open fun start() {} - - /** * Update UI title according to the current state of the chat connection */ @@ -82,10 +81,10 @@ open class BaseBluetoothChatService @JvmOverloads constructor(handler: Handler? protected fun startNotification() { val disconnectIntent = Intent(DISCONNECT_ACTION) - val disconnectPendingIntent: PendingIntent = PendingIntent.getBroadcast(this, 0, disconnectIntent, 0) + val disconnectPendingIntent: PendingIntent = PendingIntent.getBroadcast(this, 0, disconnectIntent, FLAG_IMMUTABLE) val onClickIntent = Intent(this, InitialActivity::class.java) - val pendingClickIntent = PendingIntent.getActivity(this, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val pendingClickIntent = PendingIntent.getActivity(this, 0, onClickIntent, FLAG_IMMUTABLE) val notificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, getString(R.string.bt_notification_ID)) val notification: Notification = notificationBuilder.setOngoing(true) @@ -125,4 +124,4 @@ open class BaseBluetoothChatService @JvmOverloads constructor(handler: Handler? } // private BluetoothSocket socket = null; -} \ No newline at end of file +} diff --git a/app/src/main/kotlin/io/treehouses/remote/bases/PermissionActivity.kt b/app/src/main/kotlin/io/treehouses/remote/bases/PermissionActivity.kt index 115a3654a..c9fdf2ce3 100644 --- a/app/src/main/kotlin/io/treehouses/remote/bases/PermissionActivity.kt +++ b/app/src/main/kotlin/io/treehouses/remote/bases/PermissionActivity.kt @@ -39,11 +39,21 @@ abstract class PermissionActivity : AppCompatActivity() { } fun requestPermission() { - if (!checkPermission(Manifest.permission.ACCESS_FINE_LOCATION) || !checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION) || !checkPermission(Manifest.permission.CHANGE_WIFI_STATE)) { + if (!checkPermission(Manifest.permission.ACCESS_FINE_LOCATION) || + !checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION) || + !checkPermission(Manifest.permission.CHANGE_WIFI_STATE) || + !checkPermission(Manifest.permission.BLUETOOTH) || + !checkPermission(Manifest.permission.BLUETOOTH_ADMIN) || + !checkPermission(Manifest.permission.BLUETOOTH_CONNECT) || + !checkPermission(Manifest.permission.BLUETOOTH_CONNECT)) { ActivityCompat.requestPermissions(this, arrayOf( - Manifest.permission.CHANGE_WIFI_STATE, - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION + Manifest.permission.CHANGE_WIFI_STATE, + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION, + Manifest.permission.BLUETOOTH, + Manifest.permission.BLUETOOTH_ADMIN, + Manifest.permission.BLUETOOTH_CONNECT, + Manifest.permission.BLUETOOTH_SCAN, ), PERMISSION_REQUEST_WIFI) } else { statusCheck()