GithubHelp home page GithubHelp logo

Comments (3)

Dumankrg2019 avatar Dumankrg2019 commented on June 2, 2024

tv_device_selected, Maybe you need use permission on run time.

` private fun hasConnectBluetooth() =
ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
private fun hasScanBluetooth() =
ActivityCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED

private fun requestPermissions() {
    var permissionsToReques = mutableListOf<String>()
    if(!hasScanBluetooth()) {
        permissionsToReques.add(Manifest.permission.BLUETOOTH_SCAN)
    }
    if(!hasConnectBluetooth()) {
        permissionsToReques.add(Manifest.permission.BLUETOOTH_CONNECT)
    }
    if(permissionsToReques.isNotEmpty()) {
        ActivityCompat.requestPermissions(this, permissionsToReques.toTypedArray(), 0)
    }
}
override fun onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<out String>,
    grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)

    if(requestCode == 0 && grantResults.isNotEmpty()) {
        for(i in grantResults.indices) {
            if(grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                Log.e("permission is:", " ${permissions[i]} разрешено")
                initView()
            }
        }
    }
}`

and use requestPermissions fun in your activity or fragment

from printooth.

tspoke avatar tspoke commented on June 2, 2024

Since android 12 you need to add two extras permissions, depending on your need but in my case I do this using Dexter to request permissions :

final List<String> permissions = new ArrayList<>();
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
permissions.add(Manifest.permission.BLUETOOTH);
permissions.add(Manifest.permission.BLUETOOTH_ADMIN);
        
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
    permissions.add(Manifest.permission.BLUETOOTH_CONNECT);
    permissions.add(Manifest.permission.BLUETOOTH_SCAN);
}

Dexter.withContext(requireActivity())
                .withPermissions(permissions)
                ....

from printooth.

salihinalfarizi avatar salihinalfarizi commented on June 2, 2024

hi guys @hernando-montoya @tspoke @Dumankrg2019 , i get this issue too, so which solution need to implement for this issue?

from printooth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.