2011-03-28 178 views
4

应用内结算我使用下面的代码:在安卓

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

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

基本上下文似乎大多不需要,一般建议似乎不使用它。 查看其他问题:What's the difference between the various methods to get a Context?

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

有一种方法可以测试市场应用程序是否支持应用程序内结算,即应用程序内结算参考中所述的某处。我认为这样做是值得的。

+0

感谢终于得到解决方案:) – Vijay 2011-05-05 13:47:49

0

我正在测试一个旧的Android设备,它有一个干净的系统安装。这没有一个谷歌市场应用程序的副本(帽子提示@sstn)。

因此,我使用Google帐户登录,然后启动市场。这促使我同意条款,Google Play应用出现在应用列表中。

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