【问题标题】:Problems binding Google InAppBillingService绑定 Google InAppBillingService 时出现问题
【发布时间】:2015-01-21 21:26:09
【问题描述】:

我正在尝试使用来自here 的参考来实施应用内计费

我按照说明进行操作,但在绑定 InAppBillingService 时遇到了问题。 我的 ServiceConnection 的 onServiceConnected(...) 方法似乎永远不会被调用,而该方法负责创建我的 InAppBillingService 接口。

此外,context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE) 每次都返回 false,表示存在某种问题。也许 InAppBilling 由于某种原因不可用,isBillingSupported(...) 返回 false。我没有使用模拟器。

这是我的课:

public class GoogleShop extends Shop {

    private ServiceConnection serviceConnection;
    private IInAppBillingService service;

    public GoogleShop() {
        this.serviceConnection = new ServiceConnection() {
            @Override
            public void onServiceDisconnected(ComponentName name) {
                service = null;
            }

            @Override
            public void onServiceConnected(ComponentName name, IBinder binder) {
                service = IInAppBillingService.Stub.asInterface(binder);
            }
        };
    }

    public void bindService(Context context) {
        Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");

        System.out.println("InAppBillingAvailable : " + GoogleShop.isBillingAvailable(context));
        if (context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE))
            return;
        else
            throw new RuntimeException("BindService returned false");
    }

    public ServiceConnection service() {
        return serviceConnection;
    }

    public static boolean isBillingAvailable(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
        List<ResolveInfo> list = packageManager.queryIntentServices(intent, 0);
        return list.size() > 0;
    }
}

还有,我没有忘记添加

<uses-permission android:name="com.android.vending.BILLING" />

到我的清单

【问题讨论】:

    标签: java android in-app-billing


    【解决方案1】:

    你做的很艰难。请参阅此 Google 指南以准备 in app billing。 Google 有一个名为 IabHelper 的开源类,它可以为您处理 Iab,并且已经看到了许多迭代,因此它将优于您现在创建的。

    你也可以看到this code.google link

    【讨论】:

    • 谢谢,这绝对有帮助:)
    猜你喜欢
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2023-01-19
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多