D
D
Dmtm2020-04-07 06:02:54
Android
Dmtm, 2020-04-07 06:02:54

Why isn't a SecurityException thrown when using FusedLocationProviderClient?

//в Activity
 override fun onStart() {
        super.onStart()
        val res = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED
        Log.d(TAG, "ACCESS_FINE_LOCATION: $res") //<=== тут false

        var fusedLocationProviderClient: FusedLocationProviderClient? = null
        val locationCallback = LocationCallback()
        try {
            fusedLocationProviderClient= LocationServices.getFusedLocationProviderClient(this)
            fusedLocationProviderClient.requestLocationUpdates(LocationRequest(), locationCallback, Looper.myLooper())
        } catch (e: Throwable) { //<==== почему нет SecurityException? (и вообще любого Exception?)
            Log.d(TAG, e.javaClass.name) 
        } finally {
            fusedLocationProviderClient?.removeLocationUpdates(locationCallback)
            fusedLocationProviderClient = null
        }

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-04-07
@zagayevskiy

Well, after checking and getting PERMISSION_DENIED, you need to explicitly request a permishin.
https://developer.android.com/training/permissions...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question