Android google play billing 4 "Too many receivers, total of 1000, registered for pid: 31647, callerPackage: ... "

Viewed 229

I'm getting this crash only on some devices. This happens right when I try to build a new BillingClient.

And I can't properly debug this issue since it doesn't happen on any of my devices. Again, this doesn't happen in every device, Only in, like 10% of devices that installed my app.

Here's how I init billing:

class BillingManager(
    private val context: Context,
    private val firebase: FirebaseManager,
    private val storage: SharedPreferenceStorage
) {

    private var billingClient: BillingClient? = null
    val initBillingResponse = MutableLiveData<Boolean?>()

    private val startConnectionListener = object : BillingClientStateListener {
        override fun onBillingSetupFinished(result: BillingResult) {
            if (result.isResponseOk()) {
                getSKUs()
                checkSubscription()
                initBillingResponse.postValue(true)
            } else {
                initBillingResponse.postValue(false)
            }
        }

        override fun onBillingServiceDisconnected() {
            initBillingResponse.postValue(false)
        }
    }
  
    init {
        initBilling()
    }

    private fun initBilling() {
        initBillingResponse.postValue(null)

        try {
            billingClient = BillingClient.newBuilder(context)
                .enablePendingPurchases()
                .setListener { billingResult, purchases ->
                    if (billingResult.isResponseOk()) {
                        acknowledgePurchases(purchases)
                        checkSubscription()
                    } else {
                        billingResult.responseCode
                    }
                }
                .build()

            billingClient?.startConnection(startConnectionListener)
        } catch (e: Throwable) {
            e.printStackTrace()
            FirebaseCrashlytics.getInstance().recordException(e)
            initBillingResponse.postValue(false)
        }
    }

    // Other functions
}
0 Answers
Related