我正在使用以下代码:
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
但仍显示如下:
无法绑定到 MarketBillingService
你能指出我的错误吗?
答案 0 :(得分:0)
我不知道这是否是您的问题的原因,但您在getBaseContext()上使用bindService()。您是否有理由不在服务实例上调用bindService()?这就是示例服务的作用。
基本上下文似乎大多不需要,一般建议似乎不使用它。 请参阅另一个问题:What's the difference between the various methods to get a Context?
除此之外,您需要在您的设备上安装Android Market应用程序的最新版本(或至少是最新版本),不过我认为它会自行更新。
有一种方法可以测试市场应用是否支持In-App Billing,在应用内结算参考中描述。我认为这样做是值得的。
答案 1 :(得分:0)
我正在测试一台安装了干净系统的旧Android设备。这里没有Google Market应用程序的副本(帽子提示@sstn)。
所以我使用Google帐户登录,然后推出了Market。这促使我同意条款,Google Play应用程序出现在应用程序列表中。
然后我删除并重新安装了我的应用程序,它正确绑定到服务!