2011-04-09 58 views
4

我试图在基于Sample Application的应用中实施应用内结算。 但是bindService总是返回falseAndroid的应用内结算和bindService

这是我的。 AndroidManifest.xml中

<service android:name="tv.app.billing.BillingService" /> 

Preferences.java(需要开始从首屏购买):

protected void onCreate(Bundle savedInstanceState) { 
    mBillingService = new BillingService(); 
    mBillingService.setContext(this); // tried to use getApplicationContext also 

BillingService.java: 公共类BillingService有扩展服务实现ServiceConnection {

/** 
* Binds to the MarketBillingService and returns true if the bind 
* succeeded. 
* @return true if the bind succeeded; false otherwise 
*/ 
private boolean bindToMarketBillingService() { 
    try { 
     if (Debug.DEBUG) { 
      Log.i(TAG, "binding to Market billing service"); 
     } 
     boolean bindResult = bindService(
       new Intent(Consts.MARKET_BILLING_SERVICE_ACTION), 
       this, // ServiceConnection. 
       Context.BIND_AUTO_CREATE); 

     if (bindResult) { 
      return true; 
     } else { 
      Log.e(TAG, "Could not bind to service."); 
     } 
    } catch (SecurityException e) { 
     Log.e(TAG, "Security exception: " + e); 
    } 
    return false; 
} 

而在logcat中我看到:

WARN/ActivityManager(48): Unable to start service Intent { act=com.android.vending.billing.MarketBillingService.BIND }: not found 

什么我需要在这里纠正?

+1

奇怪,但它并不只在模拟器上工作和实际工作的设备上。可能,我应该等待服务启动? – 2011-04-09 17:04:35

回答

8

好吧,它不能在模拟器上测试(因为它没有Android Market的?)。官方网站的 Testing In-app Billing节说

不能使用Android模拟器 测试应用内结算

1

您是否在清单中声明了接收者? (source

<receiver android:name="BillingReceiver"> 
     <intent-filter> 
     <action android:name="com.android.vending.billing.IN_APP_NOTIFY" /> 
     <action android:name="com.android.vending.billing.RESPONSE_CODE" /> 
     <action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" /> 
     </intent-filter> 
    </receiver> 

引用:

在示例应用程序, BillingReceiver是 的BroadcastReceiver该处理 广播意图从Android 市场应用和BillingService有 是服务发送请求到 Android Market应用程序

+0

是的,它在那里。 – 2011-04-09 17:03:00

+0

耻辱:-)还有'INTERNET'权限? – 2011-04-09 17:06:11

+0

是的(但根据示例应用程序不需要;) – 2011-04-09 17:07:28

1

请把bindToMarketBillingService()onServiceConnected

因为当它完成绑定,它会调用倒流,回到IBinder到您的连接。

我100%肯定这会工作!

+0

bindToMarketBillingService()其中是方法 – NareshRavva 2015-01-06 14:08:49