question

nonabona-0274 avatar image
0 Votes"
nonabona-0274 asked FredrikBrynolfsson-4747 answered

In App Purchasing using Google BillingClient

Hi, I am having a hard time setting up In-app purchases in my Xamarin native android app.

I am using XFInAppBilling which uses the new Xamarin.Android.Google.BillingClient packages from Nuget.
XFInAppBilling also uses Plugin.CurrentActivity.


In my AndroidManifest I have (but i've read with the new 3.0 billing library its not required)

 <uses-permission android:name="com.android.vending.BILLING" />


This is how my MainActivity.cs looks like:

 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     Xamarin.Essentials.Platform.Init(this, savedInstanceState);
     SetContentView(Resource.Layout.activity_main);
     CrossCurrentActivity.Current.Init(this, savedInstanceState);

     var toolbar = FindViewById<AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.toolbar);
     SetSupportActionBar(toolbar);

     XFInAppBillingImplementation xFInAppBilling = new XFInAppBillingImplementation();

     bool billingConnected = xFInAppBilling.ConnectAsync().Result;

  }

I have already published my APK to google console for internal testing. And I have an active in-app product listed on Google play console.


When I debug my app from visual studio on an actual device; in the ConnectAsync() method of XFInAppBillingImplementation.cs:

 public async Task<bool> ConnectAsync()
 {
     try
     {
         _tcsConnect = new TaskCompletionSource<bool>();

         BillingClient = BillingClient.NewBuilder(CurrentContext).EnablePendingPurchases().SetListener(this).Build();

         BillingClient.StartConnection(this);

         return await _tcsConnect?.Task;             //hangs here
     }
     catch (Exception ex)
     {

         throw ex;
     }
 }

my app just hangs at the return await _tcsConnect?.Task line.


Looking for guidance to setting up iap.



dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

FredrikBrynolfsson-4747 avatar image
0 Votes"
FredrikBrynolfsson-4747 answered

Hi
I had a similar problem with another BillingClient framework.
Mine was solved by adding await to the function call:

  bool billingConnected = await xFInAppBilling.ConnectAsync();


Hope it helps!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.