Jerry Agin
Jerry Agin

Reputation: 719

BillingClient isFeatureSupported returns SERVICE_DISCONNECTED

I'm working with the Google Billing Library Version 5. I've pretty much gotten my code to do the right thing. I tested it on hardware devices running API levels 16, 23, 28, and 32.

Then I did a factory reset on the device running API level 23. I wanted to establish a brand new Google ID to test the billing library. It's a Samsung Galaxy S5 running Android M. Purchasing no longer works. billingClient.isReady returns false, and billingClient.isFeatureSupported returns SERVICE_DISCONNECTED.

onBillingServiceDisconnected is not being called.

billingClient.queryPurchasesAsync() does work. It returns an OK response code and reports zero purchases.

My code runs fine on my other devices, and it used to run fine on the Galaxy S5 until I reset it and gave it a new user ID.

https://developer.android.com/google/play/licensing/setting-up says I should be running on a device that has the Google Play client pre-installed. The Applications Manager shows a Google Play Store app with the same version number as my other devices. Ditto for Google Play Services. The Play Store app tells me it is up to date.

What am I missing?

public void doPurchase( Activity activity )
{
    billingClient = BillingClient.newBuilder(activity).enablePendingPurchases()
            .setListener(this).build();
    if ( ! billingClient.isReady() )
        Log.i( appName, "Billing client is not ready" );
    BillingResult billingResult = billingClient.isFeatureSupported( BillingClient.FeatureType.PRODUCT_DETAILS );
    if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
    {
        Log.i( appName, String.format( "feature not supported %s", billingResult.toString() ) );
        return;
    }
    billingClient.startConnection(new BillingClientStateListener()
    {
        public void onBillingSetupFinished( @NonNull BillingResult billingResult )
        {
            if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
            {
                Log.i( appName, String.format( "billing setup response code  %s", billingResult.toString() ) );
                return;
            }
            launchPurchase( activity );
        }
        public void onBillingServiceDisconnected()
        {
            Log.i( appName, "Disconnected" );
        }
    });
}
private void launchPurchase( final Activity activity )
{
    ImmutableList<QueryProductDetailsParams.Product> productList
            = ImmutableList.of( QueryProductDetailsParams.Product.newBuilder()
                .setProductId( SKU_BUY )
                .setProductType( BillingClient.ProductType.INAPP)
                .build());
    QueryProductDetailsParams.Builder builder = QueryProductDetailsParams.newBuilder();
    builder.setProductList( productList );
    billingClient.queryProductDetailsAsync( builder.build(),
            new ProductDetailsResponseListener() {
                @Override
                public void onProductDetailsResponse( @NonNull BillingResult billingResult,
                                                      @Nullable List<ProductDetails> list ) {
                    if ( billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK )
                    {
                        Log.i( appName, String.format( "product details response code  %s", billingResult.toString() ) );
                        return;
                    }
                    if ( list == null || list.size() <= 0 )
                    {
                        Log.i( appName, "no products found" );
                        return;
                    }
                    ImmutableList<BillingFlowParams.ProductDetailsParams> deetsParams = ImmutableList.of(
                            BillingFlowParams.ProductDetailsParams.newBuilder()
                                    .setProductDetails( list.get( 0 ) )
                                    .build() );
                    BillingFlowParams purchaseParams = BillingFlowParams.newBuilder()
                            .setProductDetailsParamsList( deetsParams )
                            .build();
                    billingClient.launchBillingFlow( activity, purchaseParams );
                }
            } );
}

Upvotes: 1

Views: 1292

Answers (0)

Related Questions