2017-08-25 51 views
-1

我在我的片段下面的代碼(不是所有的代碼,但一般的部):Xamarin.Android應用內結算OnProductPurchased不工作

public void BuySubscription(int number) 
    { 
     string vvalue = Security.Unify(
       new string[] { 
        SpecialStringOne, 
        SpecialStringTwo, 
        SpecialStringThree, 
        SpecialStringFour, 
        SpecialStringFive, 
        SpecialStringSix, 
       new int[] { 3, 2, 0, 5, 1, 4 }); 

     _serviceConnection = new InAppBillingServiceConnection(Activity, vvalue); 

     _serviceConnection.OnConnected += async() => 
     { 
      await GetInventory(); 

      _serviceConnection.BillingHandler.OnProductPurchased += delegate 
      { 
       // Reaction if product was bought 
       ExtraTools.StringWorker.ShowMessage("I have bought it!", false);    
      }; 

      _serviceConnection.BillingHandler.BuyProduct(products[number]); 
     }; 

     _serviceConnection.Connect(); 
    } 

而且我從來沒有得到OnProductPurchased事件。

這裏面MainActivity通用代碼:

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) 
    { 
     Fragments.BillingFragment billingFragment = new Fragments.BillingFragment(); 
     base.OnActivityResult(requestCode, resultCode, data); 
     if (billingFragment != null) 
     { 
      try 
      { 
       Fragments.BillingFragment._serviceConnection.BillingHandler.HandleActivityResult(requestCode, resultCode, data); 
       int code = data.GetIntExtra("ResponseCode", 2); 
      } 
      catch (NullReferenceException exc) 
      { 
       Toast.MakeText(Application.Context, "Some error occurred", ToastLength.Short).Show(); 
      } 

     } 
    } 

什麼是錯的內部片段?請幫幫我。

回答

0

我從來沒有想過,它可能是我的問題的原因,但是當我從我的MainActivity刪除LaunchMode = LaunchMode.SingleInstance,我得到了要求的事件。

這很奇怪!