2011-03-28 175 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應用出現在應用列表中。

然後我刪除並重新安裝我的應用程序,它正確地綁定到服務!