Android 中的应用程序计费
我正在使用以下代码:
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
但它仍然显示为:
无法绑定到 市场计费服务
你能指出我的错误吗?
I am using following code:
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);
}
}
}
I have also added the IMarketBillingService.aidl
but still it show like:
Could not bind to the
MarketBillingService
Can you point out my mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是否是您问题的原因,但您正在 getBaseContext() 上使用 bindService() 。您不在服务实例上调用bindService() 是否有原因?这就是示例服务的作用。
基本上下文似乎基本上是不需要的,一般建议似乎不使用它。
请参阅另一个问题:有什么区别 。
除此之外,您需要在设备上安装最新(或至少是最近)版本的 Android Market 应用程序,尽管我假设它会自行更新
有一种方法可以测试市场应用程序是否支持应用程序内结算,在应用程序内结算参考中的某处进行了描述。我认为做这项检查是值得的。
I don't know if this is the cause for your problem, but you are using bindService() on getBaseContext(). Is there a reason that you don't call bindService() on the service instance? That's what the example service does.
The base context seems to be mostly unneeded and the general advice seems to not use it.
See the other question: What's the difference between the various methods to get a Context?
Besides that, you need to have the newest (or at least a recent) version of the Android Market App on your device, although I assume that it updates itself.
There is a way to test if the market app supports In-App Billing, somewhere described in the In-App-Billing reference. I assume that it is worth to do that check.
我正在一台旧的 Android 设备上进行测试,该设备安装了干净的系统。这上面没有 Google Market 应用程序的副本(帽子提示@sstn)。
所以我用谷歌帐户登录,然后启动了市场。这促使我同意条款,Google Play 应用程序出现在应用程序列表中。
然后我删除并重新安装了我的应用程序,它正确绑定到服务!
I was testing on an old Android device which had a clean system install. This didn't have a copy of the Google Market app on it (hat tip @sstn).
So I logged in with a Google account, then launched the Market. That prompted me to agree to terms and the Google Play app appeared in the list of applications.
Then I removed and reinstalled my app and it bound to the service correctly!