gpt4 book ai didi

android - Amazon IAP 不调用监听器回调(Kindle Fire、Xamarin)

转载 作者:行者123 更新时间:2023-11-29 19:10:28 27 4
gpt4 key购买 nike

我正在尝试[使用 Xamarin 在 Android 项目中实现亚马逊应用内购买。

设置

亚马逊的官方 Xamarin SDK 不支持较新的 64 位设备,因此我创建了我的 own Java library binding使用亚马逊的 Java SDK。 ( Documentation for the Java version )

Xamarin 为 PurchasingService 生成的绑定(bind)如下所示:

namespace Com.Amazon.Device.Iap
{
[Register ("com/amazon/device/iap/PurchasingService", DoNotGenerateAcw = true)]
public sealed class PurchasingService : Object
{
//
// Static Fields
//
private static IntPtr IS_SANDBOX_MODE_jfieldId;

[Register ("SDK_VERSION")]
public const string SdkVersion = "2.0.76.4";

internal static IntPtr java_class_handle;

private static IntPtr id_getUserData;

private static IntPtr id_getProductData_Ljava_util_Set_;

private static IntPtr id_getPurchaseUpdates_Z;

private static IntPtr id_notifyFulfillment_Ljava_lang_String_Lcom_amazon_device_iap_model_FulfillmentResult_;

private static IntPtr id_purchase_Ljava_lang_String_;

private static IntPtr id_registerListener_Landroid_content_Context_Lcom_amazon_device_iap_PurchasingListener_;

//
// Static Properties
//
internal static IntPtr class_ref {
get;
}

[Register ("IS_SANDBOX_MODE")]
public static bool IsSandboxMode {
get;
}

public static RequestId UserData {
[Register ("getUserData", "()Lcom/amazon/device/iap/model/RequestId;", "GetGetUserDataHandler")]
get;
}

//
// Properties
//
protected override IntPtr ThresholdClass {
get;
}

protected override Type ThresholdType {
get;
}

//
// Constructors
//
internal PurchasingService (IntPtr javaReference, JniHandleOwnership transfer);

//
// Static Methods
//
[Register ("getProductData", "(Ljava/util/Set;)Lcom/amazon/device/iap/model/RequestId;", "")]
public static RequestId GetProductData (ICollection<string> p0);

[Register ("getPurchaseUpdates", "(Z)Lcom/amazon/device/iap/model/RequestId;", "")]
public static RequestId GetPurchaseUpdates (bool p0);

[Register ("notifyFulfillment", "(Ljava/lang/String;Lcom/amazon/device/iap/model/FulfillmentResult;)V", "")]
public static void NotifyFulfillment (string p0, FulfillmentResult p1);

[Register ("purchase", "(Ljava/lang/String;)Lcom/amazon/device/iap/model/RequestId;", "")]
public static RequestId Purchase (string p0);

[Register ("registerListener", "(Landroid/content/Context;Lcom/amazon/device/iap/PurchasingListener;)V", "")]
public static void RegisterListener (Context p0, IPurchasingListener p1);
}
}

对于 PurchasingListener 接口(interface):

namespace Com.Amazon.Device.Iap
{
[Register ("com/amazon/device/iap/PurchasingListener", "", "Com.Amazon.Device.Iap.IPurchasingListenerInvoker")]
public interface IPurchasingListener : IJavaObject, IDisposable
{
//
// Methods
//
[Register ("onProductDataResponse", "(Lcom/amazon/device/iap/model/ProductDataResponse;)V", "GetOnProductDataResponse_Lcom_amazon_device_iap_model_ProductDataResponse_Handler:Com.Amazon.Device.Iap.IPurchasingListenerInvoker, AmazonIAP")]
void OnProductDataResponse (ProductDataResponse p0);

[Register ("onPurchaseResponse", "(Lcom/amazon/device/iap/model/PurchaseResponse;)V", "GetOnPurchaseResponse_Lcom_amazon_device_iap_model_PurchaseResponse_Handler:Com.Amazon.Device.Iap.IPurchasingListenerInvoker, AmazonIAP")]
void OnPurchaseResponse (PurchaseResponse p0);

[Register ("onPurchaseUpdatesResponse", "(Lcom/amazon/device/iap/model/PurchaseUpdatesResponse;)V", "GetOnPurchaseUpdatesResponse_Lcom_amazon_device_iap_model_PurchaseUpdatesResponse_Handler:Com.Amazon.Device.Iap.IPurchasingListenerInvoker, AmazonIAP")]
void OnPurchaseUpdatesResponse (PurchaseUpdatesResponse p0);

[Register ("onUserDataResponse", "(Lcom/amazon/device/iap/model/UserDataResponse;)V", "GetOnUserDataResponse_Lcom_amazon_device_iap_model_UserDataResponse_Handler:Com.Amazon.Device.Iap.IPurchasingListenerInvoker, AmazonIAP")]
void OnUserDataResponse (UserDataResponse p0);
}
}

我还确保修改了 Android list :

<receiver android:name = "com.amazon.device.iap.ResponseReceiver" >
<intent-filter>
<action android:name = "com.amazon.inapp.purchasing.NOTIFY"
android:permission = "com.amazon.inapp.purchasing.Permission.NOTIFY" />
</intent-filter>
</receiver>

Amazon App Tester 安装在我的 Kindle 上并配置了以下测试数据:

{
"IAP_ID":
{
"description":"One year Subscription",
"title":"My Subscription",
"itemType":"SUBSCRIPTION",
"price":20.00,
"subscriptionParent":"org.company.appid"
}
}

我有一个类的骨架来测试系统是否正常工作:

public class AmazonIAPController : Java.Lang.Object, IPurchasingListener
{
const string ProductId = "IAP_ID";
private Activity uiActivity;

public AmazonIAPController()
{
}

public void SetupIAP(Activity activity) {
uiActivity = activity;
PurchasingService.RegisterListener(uiActivity, this);

// test that the Amazon system works
PurchasingService.Purchase(ProductId);
}

public void OnResume(Activity activity) {
uiActivity = activity;
PurchasingService.RegisterListener(uiActivity, this);

//PurchasingService.UserData;
PurchasingService.GetPurchaseUpdates(false);
PurchasingService.GetProductData(new string[] { ProductId });

}

public void OnProductDataResponse(ProductDataResponse response) {
var status = response.GetRequestStatus();

Debug.WriteLine("*****OnProductDataResponse");
}

public void OnPurchaseResponse(PurchaseResponse response) {
var status = response.GetRequestStatus();
Debug.WriteLine("*****OnPurchaseResponse");
}

public void OnPurchaseUpdatesResponse(PurchaseUpdatesResponse response) {
var status = response.GetRequestStatus();
Debug.WriteLine("*****OnPurchaseUpdatesResponse");
}

public void OnUserDataResponse(UserDataResponse response) {
var status = response.GetRequestStatus();
Debug.WriteLine("*****OnUserDataResponse");
}
}

测试运行

我正在尝试在我的第 5 代 Kindle Fire 上运行它。当应用程序启动时,用户会按预期收到 Amazon IAP 提示。如果执行了购买,它就会完成并且交易会正确显示在 Amazon App Tester 应用程序中。

问题

我在回调方法中设置了断点。这些断点永远不会被触发。 Debug.WriteLine 调用也不会出现在应用程序输出中。看来我的回调方法没有被调用。

最佳答案

问题的根源是 Android list 条目与 Xamarin 生成具有代码属性的 list 条目的方式发生冲突。

为了解决这个问题,我从 list 中删除了上述条目,并在 Java 绑定(bind)项目中创建了一个附加文件,其中包含 ResponseReciever 的部分类和相关的 list 属性,如下所示:

using System;
using Android.App;
using Android.Content;

namespace Com.Amazon.Device.Iap
{
[BroadcastReceiver(Name = "com.amazon.device.iap.ResponseReceiver")]
[IntentFilter(new[] { "com.amazon.inapp.purchasing.NOTIFY" })]
public partial class ResponseReceiver
{

}
}

此后, list 条目已正确生成,预期的回调开始工作。

备注:

您可能会注意到 list XML 中的 android:permission 条目不在上述属性中。我找不到引用,但我记得在某处看到不仅不需要这个条目来让 SDK 工作,而且根据 the official Android documentation,它实际上不是 action 上的有效属性。 .

关于android - Amazon IAP 不调用监听器回调(Kindle Fire、Xamarin),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45554652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com