【问题标题】:In app billing in android在android中的应用计费
【发布时间】:2011-07-24 12:08:21
【问题描述】:

我正在使用以下代码:

public class MyBillingService extends Service implements ServiceConnection
{
    String TAG = "MyBillingService";

    @Override
    public void onCreate() 
    {
        super.onCreate();
        Log.i(TAG, "onCreate");

        try {
            boolean bindResult = getBaseContext().bindService(
                new Intent(IMarketBillingService.class.getName()), this, Context.BIND_AUTO_CREATE);
            if (bindResult) {
                Log.i(TAG, "Service bind successful.");
            } else {
                Log.e(TAG, "Could not bind to the MarketBillingService.");
            }
        } catch (SecurityException e) {
            Log.e(TAG, "Security exception: " + e);
        }
    }
}

我还添加了IMarketBillingService.aidl,但它仍然显示为:

无法绑定到 市场计费服务

你能指出我的错误吗?

【问题讨论】:

    标签: android google-play billing


    【解决方案1】:

    我不知道这是否是您的问题的原因,但您在 getBaseContext() 上使用了 bindService()。您是否有理由不在服务实例上调用 bindService() ?这就是示例服务的作用。

    基本上下文似乎大部分是不需要的,一般建议似乎不使用它。 见另一个问题:What's the difference between the various methods to get a Context?

    除此之外,您需要在您的设备上安装最新(或至少是最新)版本的 Android 电子市场应用程序,尽管我认为它会自行更新。

    有一种方法可以测试市场应用程序是否支持应用内计费,在应用内计费参考中有所描述。我认为值得进行检查。

    【讨论】:

      【解决方案2】:

      我在安装了干净系统的旧 Android 设备上进行测试。这上面没有 Google Market 应用程序的副本(帽子提示@sstn)。

      所以我使用 Google 帐户登录,然后启动了 Market。这促使我同意条款,Google Play 应用出现在应用列表中。

      然后我删除并重新安装了我的应用程序并正确绑定到服务!

      【讨论】:

        猜你喜欢
        • 2013-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多