安卓应用内购买出现SecurityException "Binder invocation to an incorrect interface"错误

8
我正在尝试获取Google应用内购买服务的工作原理。
我已经将服务绑定并连接,但一旦我尝试从服务中获取一些数据,它就会崩溃,并在日志中显示以下内容:
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(...出现了错误。


我就此事进行了一些研究,并发现可能是由于错误的包名称导致的。我已按照Google文档中描述的方式包含了IInAppBillingService.aidl文件,但在导入时仍然出现了错误的包:

文件位于:src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl

但是当我导入生成的类时,Android Studio使用了这个导入路径:

import billing.IInAppBillingService;

根据文档,实际应该是这样的:
import com.android.vending.billing.IInAppBillingService;

我的项目设置还有问题吗?还是有人知道这个错误的原因吗?

非常感谢您的帮助! McFarlane

3个回答

19

我之前遇到了同样的问题并发现,aidl文件必须在src文件夹下的com.android.vending.billing包中,但你把它放在了src/main/aidl/com/android/vending/billing,这是不正确的。


0

我也遇到了同样的问题,我按照https://developer.android.com的步骤进行操作。

将IInAppBillingService.aidl文件复制到您的项目中。

如果您使用的是Android Studio,请完成以下步骤以复制该文件: 在“项目工具窗口”中导航到 src/main。 选择“文件”>“新建”>“目录”,在“新建目录”窗口中输入 aidl,然后选择“确定”。 选择“文件”>“新建”>“包”,在“新建包”窗口中输入 com.android.vending.billing,然后选择“确定”。 使用您的操作系统文件浏览器,导航到 <sdk>/extras/google/play_billing/,将 IInAppBillingService.aidl 文件复制, 然后将其粘贴到您的项目中的 com.android.vending.billing 包中。

我创建了aidl文件夹,然后在该文件夹中创建了com.android.vending.billing包,但我的import仍然是 import billing.IInAppBillingService; 我尝试在src中添加包,但IInAppBillingService.java并未生成。

enter image description here


0

我遇到了这个问题,是因为我使用了In App Billing v2,并且错误地认为它是v3版本。糟糕 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接