Skip to content

Commit

Permalink
actions: bluetooth permission newer way (fixes #1832) (#1833)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Feb 1, 2024
1 parent 4c9a7b4 commit cd063f2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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)
Expand Down Expand Up @@ -125,4 +124,4 @@ open class BaseBluetoothChatService @JvmOverloads constructor(handler: Handler?
}
// private BluetoothSocket socket = null;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cd063f2

Please sign in to comment.