0

Hi I am trying to get advertising id from AdvertisingIdClient, this is what I have but it gives me a warning Inappropriate blocking method call

How can I resolve this please

private suspend fun getAdvertisingId(): String? {
    return withContext(Dispatchers.Default) {
        try {
            AdvertisingIdClient.getAdvertisingIdInfo(ohmeApp.applicationContext).id
        } catch (exception: Exception) {
            "" // there still can be an exception for other reasons but not for thread issue
        }
    }
}

Could you please suggest what I can do to resolve this please.

enter image description here

BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • Does this answer your question? [How to make "inappropriate blocking method call" appropriate?](https://stackoverflow.com/questions/58680028/how-to-make-inappropriate-blocking-method-call-appropriate) – TheLibrarian Oct 25 '22 at 13:26
  • I tried adding `withContext(Dispatchers.IO)` but that did not work sorry – BRDroid Oct 25 '22 at 13:30
  • 1
    Dispatchers.IO is more appropriate than Default here. If that doesn't fix it, it's a false positive in the lint inspection. This inspection has been plagued with false positives since it was first introduced. They fixed some of them but not all. – Tenfour04 Oct 25 '22 at 13:32
  • That was not the point, there is a lot of discussion/explanation there about why you get that warning and how to cope with it - if it is appropriate to ignore it. – TheLibrarian Oct 25 '22 at 13:32
  • so in my case I do not need to worry about it?. is the code okay to be as it is? – BRDroid Oct 25 '22 at 14:06
  • Looks fine to me as long as you switch to Dispatchers.IO. I would suppress the warning. – Tenfour04 Oct 25 '22 at 14:38

0 Answers0