我正在努力让谷歌应用程序结算服务工作。
我到目前为止已经绑定并连接了服务,但是一旦我尝试从服务中获取某些数据,它就会崩溃并记录日志:
04-02 10:36:32.795 10569-10651/my.app.package E/IAP﹕ java.lang.SecurityException: Binder invocation to an incorrect interface
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at billing.IInAppBillingService$Stub$Proxy.getSkuDetails(IInAppBillingService.java:251)
at my.app.package.libs.clientbackend.iap.IAPHelper$FetchItemsCallable.call(IAPHelper.java:102)
at my.app.package.libs.clientbackend.iap.IAPHelper$FetchItemsCallable.call(IAPHelper.java:89)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
到目前为止,这是我的代码:
显示购买的活动:
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
一旦服务连接,IAB就会调用:
Bundle itemBundle = new Bundle();
itemBundle.putStringArrayList("ITEM_ID_LIST", new ArrayList<>(Arrays.asList(itemIds)));
Bundle detailsBundle = service
.getSkuDetails(3, context.getPackageName(), "inapp", itemBundle);
在最后一行...getSkuDetails(...
上失败,上面发布了错误。
我对此事做了一些研究,发现我们可能是由错误的包名引起的。我已经在谷歌的文档中描述了IInAppBillingService.aidl
喜欢它,但我在导入时仍然收到错误的包裹:
该文件位于:src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl
但是当我导入生成的类时,Android Studio使用此导入路径:
import billing.IInAppBillingService;
根据文件,这应该是:
import com.android.vending.billing.IInAppBillingService;
我的项目设置是否仍有问题,或者是否有人知道此错误的原因?
提前多多感谢, 麦克法兰
答案 0 :(得分:19)
我遇到了同样的问题,我发现aidl文件必须位于src文件夹的com.android.vending.billing
包中,但是你将它放在src/main/aidl/com/android/vending/billing
中这是不正确的。
答案 1 :(得分:0)
我也有同样的问题。我从https://developer.android.com
开始执行此步骤将IInAppBillingService.aidl文件复制到您的项目中。
如果您使用的是Android Studio,请完成以下步骤以复制 文件: 在“项目”工具窗口中导航到src / main。 选择文件&gt;新&gt;目录,在New Directory窗口中输入aidl,然后选择OK。 选择文件&gt;新&gt;打包,在“新建包”窗口中输入com.android.vending.billing,然后选择“确定”。 使用操作系统文件资源管理器,导航至&lt; sdk&gt; / extras / google / play_billing /,复制 IInAppBillingService.aidl文件,并将其粘贴到 项目中的com.android.vending.billing包。
我创建了aidl文件夹然后在这个文件夹中创建了包com.android.vending.billing,我的导入仍然是导入billing.IInAppBillingService;我尝试在src中添加包,但是没有生成IInAppBillingService.java。
答案 2 :(得分:0)
由于使用In App Billing v2并认为它是v3版本,我遇到了这个问题。糟糕:)