我正在使用以下代码:
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/