0

I want to request runtime permission. But it only show one request. Can someone guide me how can I achieve this in jetpack compose. I am using compose 1.1.1 and using accompanist-permissions with 0.23.1 version. I declare permission in my manifest according to this official doc..

In Manifest.xml

    <uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
    <!-- Request legacy Bluetooth permissions on older devices. -->
    <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.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation"
        tools:targetApi="s" />
    <!-- Needed only if your app makes the device discoverable to Bluetooth devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <!-- Needed only if your app communicates with already-paired Bluetooth devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-feature android:name="android.hardware.bluetooth" android:required="true"/>

I tried this piece of code

BluetoothRequestActivity.kt

class BluetoothRequestActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Theme {
                val multiplePermissionsState = rememberMultiplePermissionsState(
                    listOf(
                        Manifest.permission.BLUETOOTH,
                        Manifest.permission.BLUETOOTH_SCAN,
                        Manifest.permission.BLUETOOTH_CONNECT,
                        Manifest.permission.BLUETOOTH_ADVERTISE,
                        Manifest.permission.BLUETOOTH_ADMIN
                    )
                )
                AppBarScaffold(abc = true) {
                    BluetoothRequest(multiplePermissionsState, onCancelClick = {
                        finish()
                    })
                }
            }
        }
    }
}

Another compose function

BluetoothRequest

@Composable
fun BluetoothRequest(
    multiplePermissionsState: MultiplePermissionsState,
    onCancelClick: () -> Unit
) {
    Column {
        BluetoothRequestItem()
        BluetoothRequestContinue(multiplePermissionsState)
        BluetoothRequestCancel(onCancelClick)
    }
}

BluetoothRequestContinue

@Composable
fun BluetoothRequestContinue(multiplePermissionsState: MultiplePermissionsState) {
    MaterialButton(
        text = stringResource(R.string.continue_text),
        spacerHeight = dimensionResource(10.dp)
    ) {
        multiplePermissionsState.launchMultiplePermissionRequest()
    }
}

I am getting only single request permission like this

enter image description here

Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42
Kotlin Learner
  • 3,995
  • 6
  • 47
  • 127
  • "I am getting only single request permission like this" -- that seems to match what your code calls for. What are you expecting? – CommonsWare Sep 16 '22 at 14:39
  • I want to request permission like bluetooth, bluetooth scan, Bluetooth pairing, data transmission etc.. I need access all bluetooth feature from user... – Kotlin Learner Sep 16 '22 at 14:43

1 Answers1

2

Whatever you mentioned saying you wanted those permissions is literally covered in the dialog that shows up.

You say, "scan, pair, and data-transmission", the dialog says find (scan), connect to (pair and data-transmission), and find relative position of nearby devices (extra functionality). Try removing some of the permissions from the array, see how the dialog text changes. The user is not supposed to know the technicalities of the underlying OS, (admin, advertising). That's why it is abstracted into a simple text dialog, which states everything clearly to the user. Your code is fine,

Richard Onslow Roper
  • 5,477
  • 2
  • 11
  • 42