Android的应用内结算和bindService

时间:2011-04-09 16:51:54

标签: android binding service in-app-purchase

我正在尝试根据Sample Application在我的应用中实施应用内结算。 但bindService始终返回false

这就是我所拥有的。 的的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 extends Service实现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

我需要在这里纠正什么?

4 个答案:

答案 0 :(得分:8)

好的,它无法在模拟器上测试(因为它没有Android Market?)。 官方网站的Testing In-app Billing部分说

  

您无法使用Android模拟器   测试应用内结算

答案 1 :(得分:4)

您是对的,模拟器不支持结算,但您可以使用此测试框架:android-test-billing来测试模拟器上的应用内结算。 该框架在Horer项目中使用 - horaire de RER以简化集成。

答案 2 :(得分: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应用程序

答案 3 :(得分:1)

请将bindToMarketBillingService()放入onServiceConnected

因为当它完成绑定时,它会回调并将IBinder返回到您的连接。

我百分百肯定这会起作用!