1

I need to check if firebase messaging(FCM) is available in my Android app so I can make a decision about how I deliver/handle notifications. On Android devices, it's possible to perform a check for Google Play Services(GPS), which is good enough on stock Android. On LineageOS and similar platforms, without GPS, it's possible to install things like microG and specifically disable FCM. In this case, the check above will succeed, despite FCM being unavailable. Is there a way to check specifically if FCM is enabled/disabled? Does microG or similar bundles provide an API for this?

KENdi
  • 7,576
  • 2
  • 16
  • 31
CalumMcCall
  • 1,665
  • 4
  • 24
  • 46
  • I'm facing the same issue, did you figure a solution ? – Mosbah Oct 10 '19 at 19:16
  • No, I didn't find a solution. We added a toggle to the settings which allows the user to use a websocket for notifications, which solves the problem, but has other big downsides like high battery usage. Since this is only an issue on non-stock Android, it seems unlikely Google will add API support to deal with this particular issue. – CalumMcCall Oct 22 '19 at 14:38

1 Answers1

1

As the

FirebaseApp.getInstance() throws IllegalStateException 

you my try below solution

private val isFirebaseEnabled: Boolean
    get() {
        return try {
            FirebaseApp.getInstance() != null.   //that is always true, nevertheless it will throw exception if Firebase is not available
        } catch (e: IllegalStateException) {
            false
        }
    }
Pietrek
  • 1,420
  • 14
  • 18
  • This sounds plausible, but unfortunately I'm not longer working on this codebase and I can't test this solution, so I can't accept it unless someone can confirm it works. Thanks for the idea though! – CalumMcCall Jun 30 '20 at 12:37
  • @CalumMcCall Ur welcome, I am using that solution in prod and seems to be workin' smooth. – Pietrek Jul 09 '20 at 11:29