android - Xamarin 表单、Plugin.InAppBilling、Android:成功购买后出错
问题描述
在 Android 中成功购买后出现错误(Xamarin 表单、Plugin.InAppBilling)。但是购买是成功的,因为我可以在仪表板中看到收入。我的信用卡也被扣款了。
这是我的代码:
try
{
var productId = "";
var payLoad = "";
switch (Device.RuntimePlatform)
{
case Device.iOS:
productId = "removeAdd";
payLoad = "";
break;
case Device.Android:
productId = "removeadd";
payLoad = "payLoad";
break;
}
CrossInAppBilling.Current.InTestingMode = true;
var connected = await CrossInAppBilling.Current.ConnectAsync();
if (!connected)
{
//Couldn't connect to billing, could be offline, alert user
return;
}
//try to purchase item
var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription, payLoad);
if (purchase == null)
{
//Not purchased, alert the user
}
else
{
//Purchased, save this information
var id = purchase.Id;
var state = purchase.State;
Task task = AsyncTask();
}
}
catch (InAppBillingPurchaseException purchaseEx)
{
//Billing Exception handle this based on the type
}
catch (Exception ex)
{
Console.WriteLine(ex);
//Something bad has occurred, alert user
}
finally
{
//Disconnect, it is okay if we never connected
await CrossInAppBilling.Current.DisconnectAsync();
}
在 MainActivity.cs 中:
protected override void OnCreate(Bundle savedInstanceState)
{
//inApp
Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;
LoadApplication(new App());
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
InAppBillingImplementation.HandleActivityResult(requestCode, resultCode, data);
}
购买变量为空,仅此而已。当我再次尝试购买时,我收到已购买的消息。它适用于IOS。
解决方案
推荐阅读
- swift - 如何在 Xcode 模拟器中运行虚拟 iBeacons,而不是在物理设备中?
- ios - InAppPurchase 错误
- python - phython 中的简单数学测验
- javascript - 如何使用 jasmine spyon 使用特定选择器模拟 ngrx store.pipe
- asp.net-mvc - 如何存储 IEnumerable
在数据库中使用 ASP.NET MVC 标识 - python - 根据对象名称定义类属性
- python - 元素不可交互的硒python3.9
- c# - Teamcity CI Pipeline 无法运行已安装的 dotnet 工具 (sonarscanner)
- reactjs - 触发反应 useEffect
- python - 每次使用 open-cv Python 的任何进程/应用程序访问相机时,是否有方法/方法来检查/返回值?