android - 在 Android 应用内计费

标签 android google-play billing

我正在使用以下代码:

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 但它仍然显示如下:

Could not bind to the MarketBillingService

你能指出我的错误吗?

最佳答案

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

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

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

有一种方法可以测试市场应用程序是否支持应用程序内结算,在应用内结算引用中有所描述。我认为做那个检查是值得的。

关于android - 在 Android 应用内计费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5459783/

相关文章:

android - 无法在 Google Play 开发者控制台中选择“世界其他地方”选项

google-play - 如何阅读Play商店崩溃报告,Proguard混淆

jquery - 在没有当前上下文的情况下调用 OpenGL ES API(每个线程记录一次)

android - 如何去除 Spinner DropDownView 的阴影

java - 自动更新 Android 应用程序,无需用户点击

Android 旅馆应用程序 BillingFlowParams 生成器失败并出现 java.lang.IllegalArgumentException

android - 如何在 Android 上测试自动续订订阅

android - com.android.vending.billing.PURCHASES_UPDATED 什么时候广播?

android - 用居中的项目填充 recyclerview

Android 平板电脑应用程序模板