【问题标题】:Android cordova plugin with callback带有回调的 Android 科尔多瓦插件
【发布时间】:2013-11-10 01:44:23
【问题描述】:

我正在将 IOS phonegap 插件转换为 android。在IOS中有这样的插件调用

cordova.exec('InAppPurchaseManager.requestProductsData', callbackName, {productIds: productIds});

这行代码使用原生层从 itues 商店获取产品详细信息。一旦这个消息被发送到本机层,它就会发出一个异步请求来获取产品详细信息。一旦它有了产品,它就会进行调用

NSString *js = [NSString stringWithFormat:@"%@.apply(plugins.inAppPurchaseManager, %@);", callback, [callbackArgs cdvjk_JSONSerialize]];
    [command writeJavascript: js];

在上面一行中,回调变量保存了调用插件时参数 callbackName 传递的值。我怎样才能在android中做同样的事情?

插件没有在android中接收回调名称值的选项

public PluginResult execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException

在来自phonegap的android中我正在使用这种方法

cordova.exec(callbackName, null, "MyPluginClass", "getProducts", productIds);

如何在 android 中实现相同的功能?

谢谢

【问题讨论】:

    标签: java android ios cordova phonegap-plugins


    【解决方案1】:

    您必须使用 Google Play Stores In App Billing 服务。 GitHub 上的这个项目有一些很好的例子:

    https://github.com/poiuytrez/AndroidInAppBilling

    我没有时间自己为 IOS 和 Android 创建一个代码库,但我计划在未来......我最终做的是以下内容,添加单独的层可能会更快但我当时只是想让它工作,并且将来会重构......这是我的做法,需要对 Android GitHub 项目进行最少的修改:

               if ( window.plugins.InAppPurchasePlugin ) {
    
                // launch the ios in app purchase MakePurchase function....
                var quantity = 1;
    
                window.plugins.InAppPurchasePlugin.buyProduct( config.gratitudeIosInAppProductId, quantity, buyProductError );
            }
            else {
    
                if ( window.plugins.inappbilling ) {
    
                    window.plugins.inappbilling.buy( androidBuySuccessHandler, buyProductError, config.gratitudeAndroidInAppProductId );
                }
                else {
    
                    kendoConsole.log( 'no inappbilling?' );
                }
            }
    

    【讨论】:

    • 您好,感谢您的回复。我正在使用 google In ap 计费服务。但我试图重用当前phonegap源代码中存在的回调以避免更多的编码。你知道如何在android中接收回调参数吗?
    猜你喜欢
    • 2017-01-27
    • 2015-05-19
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 2015-10-13
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    相关资源
    最近更新 更多