Am having trouble implementing a conditional structure for the BillingClient class method queryPurchases(String y) to check if user has an active subscription and let him download an image in the wallpaper app else prevent him from doing so. Am having trouble getting a comparison target for the if method here is the code am using

 case R.id.cv_download:
                //This is where the app's business logic goes
                //create a new BillingClient class
                 final BillingClient myclient= BillingClient.newBuilder(getActivity()).build();
                 //Establish connection to google play
                 myclient.startConnection(new BillingClientStateListener() {
                     @Override
                     public void onBillingSetupFinished(BillingResult billingResult) {
                         //The building client is ready you can setup purchases here
                         switch(billingResult.getResponseCode()){
                             case OK:
                                 myclient.queryPurchases(BillingClient.SkuType.SUBS);
                                 //I need a conditional structure here that lets me check if user has active
                                   subscription

                         }

                     }

                     @Override
                     public void onBillingServiceDisconnected() {
                    //Inform user that its not working and he should try some other time
                         Toast.makeText(getActivity(),"Connection Problems, Try Again Later",Toast.LENGTH_LONG).show();
                     }
                 });
                 //Implement conditional structure to check if user has subscription and then let him download

                 anImage      = ((BitmapDrawable) ivRandom.getDrawable()).getBitmap();
                saveImageToExternalStorage(anImage);
                Toast.makeText(getActivity(), "Download successfuly", Toast.LENGTH_SHORT).show();

                break;

You have two operations depending on you start app approach. I mean if you always require login each time an App is started.

In that case when the user attempt to login simply return the account status in whatever way you want so that you can check the value and see if the account is active or not.

Another method is to request an account status feom your database to see if the account is active or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.