4

好吧,所以我一直在努力解决这个问题,我不会来这里寻找某人为我做我的工作,因为我一直在进行故障排除和修复每一个LogCat中的错误消息。我正在使用Andengine开发Android游戏(这可能是问题的一部分,所以熟悉它可能会有所帮助)。我没什么特别的想法,我的游戏活动都是单一场景,没有任何物理或其他类似的东西,只是一些精灵和纹理。我还将Andengine用于我游戏中的所有其他活动,因为我觉得这是一种非常简单的方法来设置图形吸引人的屏幕。其中一个屏幕是我的应用内商店,用户可以购买平面包和新的精灵。这一切的计费部分很好,购买到市场,并没有太复杂...在应用程序BIlling待定intents和切换活动的问题

当用户点击购买,市场屏幕弹出并加载他们选择的产品(这些是真正的产品,而不是Android测试,虽然游戏没有发布)。无论我使用的是“Android 2.0”实现(它是游戏堆栈的一部分),还是我使用“Android 1.6”实现,它都是它自己的堆栈的一部分,市场屏幕会弹出当前活动。我更愿意使用Android 2.0实现,但如果我只能获得1.6的工作,我会采取的。因此,无论如何,当用户使用后退按钮取消购买或用信用卡完成购买时,问题就会出现,导致市场屏幕消失,应用程序开始一个新的活动,这只是一个黑屏(最终时间并导致一个力量关闭)。购买通过确定,但用户不会获得该产品,因为游戏力量在我们到达代码以更改用户在游戏中的物品之前退出。现在对于一些代码,我使用这个教程(http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html),而不做任何改变。 BillingHelper类最重要,因为它包含requestPurchase()方法和startBuyPageActivity()方法。我打电话要求购买从我的店面活动是这样的:

  BillingHelper.requestPurchase(StoreFront.this, itemID); 

,并在店面我有这个东西的OnCreate(如告诉由啧啧做):

 startService(new Intent(mContext, BillingService.class)); 
    BillingHelper.setCompletedHandler(mTransactionHandler); 

...

//some handler that billing needs 
public Handler mTransactionHandler = new Handler(){ 
    public void handleMessage(android.os.Message msg) { 
     Log.i(TAG, "Transaction complete"); 
     Log.i(TAG, "Transaction status: "+BillingHelper.latestPurchase.purchaseState); 
     Log.i(TAG, "Item purchased is: "+BillingHelper.latestPurchase.productId); 

     if(BillingHelper.latestPurchase.isPurchased()){ 
      //TODO do something here if we've completed our latest purchase, 
      //this should be with the status bar notifications and 
      //saved preferences 
     } 
    }; 

}; 

所以我不认为问题在那里。这是一些我曾尝试从店面调用带有各种参数作为“ActivityContext”如StoreFront.this,getApplicationContext()BillingHelper

protected static void requestPurchase(Context activityContext, String itemId){ 
    if (amIDead()) { 
     return; 
    } 
    Log.i(TAG, "requestPurchase()"); 
    Bundle request = makeRequestBundle("REQUEST_PURCHASE"); 
    request.putString("ITEM_ID", itemId); 
    try { 
     Bundle response = mService.sendBillingRequest(request); 

     //The RESPONSE_CODE key provides you with the status of the request 
     Integer responseCodeIndex = (Integer) response.get("RESPONSE_CODE"); 
     //The PURCHASE_INTENT key provides you with a PendingIntent, which you can use to launch the checkout UI 
     PendingIntent pendingIntent = (PendingIntent) response.get("PURCHASE_INTENT"); 
     //The REQUEST_ID key provides you with a unique request identifier for the request 
     Long requestIndentifier  = (Long) response.get("REQUEST_ID"); 
     Log.i(TAG, "current request is:" + requestIndentifier); 
     C.ResponseCode responseCode = C.ResponseCode.valueOf(responseCodeIndex); 
     Log.i(TAG, "REQUEST_PURCHASE Sync Response code: "+responseCode.toString()); 

     startBuyPageActivity(pendingIntent, new Intent(), activityContext); 
    } catch (RemoteException e) { 
     Log.e(TAG, "Failed, internet error maybe", e); 
     Log.e(TAG, "Billing supported: "+isBillingSupported()); 
    } 
} 

的相关部分,静态上下文存储在别处,存储静态活动在其他地方,getBaseContext()什么是我能做可能想到...

以下是其他相关活动

private static void startBuyPageActivity(PendingIntent pendingIntent, Intent intent, Context context){ 
    //android 1.6 method 
    try { 
     pendingIntent.send(context, 0, intent);   
    } catch (CanceledException e){ 
     Log.e(TAG, "startBuyPageActivity CanceledException"); 
    } 
} 

没什么特别的,我只是希望用户返回到我的任何各种活动(最好店面),当他们购买物品或在此过程中向后退。请帮助!

编辑:我想要任何可能的解决方案,以便在购买完成后,即使是最麻烦的解决方案,也可以让应用内结算返回到我的应用。

编辑

什么问题的logcat的和方法调用:

"BillingService Starting", 
    BillingHelper.setCompletedHandler(), 
    StoreFront.onStart() called, 
    StoreFront.onResume() called, 
    "BillingService Service starting with onCreate", 
    "BillingService Market Billing Service Successfully Bound", 
    "BillingService Market Billing Service Connected", 
    BillingHelper.instantiateHelper(), 
    then this is where I actually click the buy button in the store (all of that runs just when opening StoreFront): 
    BillingHelper.setCompletedHandler(), 
    BillingHelper.isBillingSupported(), 
    BillingHelper.amIDead(), 
    BillingHelper.makeRequestBundle(), 
    "BillingService isBillingSupported response was: RESULT OK", 
    BillingHelper.requestPurchase(), 
    BillingHelper.amIDead(), 
    "BillingService requestPurchase()", 
    BillingHelper.makeRequestBundle(), 
    "BillingService current request is ......", 
    "BillingService REQUEST PURCHASE Sync Response code: RESULT OK", 
    BillingHelper.startBuyPageActivity(), 
    "BillingService Recieved action: com.android.vending.billing.RESPONSE CODE", 
    "BillingService checkResponseCode got requestID..." 
    "BillingService checkResponseCode go responseCode RESULT ERROR" 
    (this is because I can't purchase on this device), 
    and then I get an Error message saying: "E 32427 Surface surface (identity=5925) is invalid, err=-19 (No such device)" and from there nothing works anymore. 

也对我有不同的电话(另一个开发人员,我有工作,谁可以真正买东西,用这种试验在它但仍然得到黑屏错误),他从来没有得到你在评论中提到的处理程序消息

编辑:如果我必须猜测错误的位置,我会说这是这个

06-16 11:20:23.635: DEBUG/dalvikvm(3807): GC_EXPLICIT freed 53K, 45% free 3710K/6663K, external 1K/513K, paused 102ms 
06-16 11:20:23.885: ERROR/Surface(3807): surface (identity=158) is invalid, err=-19 (No such device) 
06-16 11:20:23.905: ERROR/Surface(3807): surface (identity=158) is invalid, err=-19 (No such device) 
06-16 11:20:23.905: ERROR/Surface(3807): surface (identity=158) is invalid, err=-19 (No such device) 
06-16 11:20:23.905: ERROR/Adreno200-EGL(3807): egliSwapWindowSurface: unable to dequeue native buffer 

请注意,Andengine库预计中断的异常是红鲱鱼。

另外(我希望这是允许在这里)我会提供解决方案的贝宝奖励。如果这是违反SO的条款,那就删除这一行,请不要关闭这个问题。

+1

您是否从您的处理程序中获得“交易完成”和“购买的商品是:”?即处理程序被称为 – Blundell 2011-06-15 20:59:44

+0

不,我其实不是,现在你提到它。购买肯定是通过和收取,因为它出现在我的商家帐户,但我没有看到它在LogCat中。这是否意味着你知道问题是什么(如果你是我的个人救星)。 – 2011-06-15 22:54:06

+1

什么是你的LogCat,InApp tut有很多注销,所以你的logcat可以显示它的停止位置。看看BillingHelper.java中的verifyPurchase(字符串,字符串)方法,这很可能是您的最高 – Blundell 2011-06-16 07:58:55

回答

5

我可能知道什么是错的,我有一个测试要你做。购买屏幕在用户取消购买或完成购买后执行结束通话。对于我来说,由于某种原因,完成调用正在缓慢进入当前正在运行的活动中(CLOSING ???)。

下面是从日志中的相关行:

十一月6日至16日:20:22.774:WARN/ActivityManager(132):为HistoryRecord重复结束请求{40ace828 com.android.vending/.billing.InAppBuyPageActivity}

我想我在我的代码的问题解决了这个问题是我不记得我做了什么(也许没叫在完成我的购买完整的处理程序...)

我什么都不知道关于Andgen,但是如果完成呼叫在主Andgen活动上被呼叫会发生什么?我想它会停止执行,你可能会得到一个黑屏和应用程序崩溃。

所以要测试这个,请为您购买页面创建一个单独的活动。不需要很复杂 - 也许它只是在启动后购买一种罐装产品。运行你的代码,看看它是否仍然给你的厄运黑屏。我敢打赌:它可能会退出游戏,但我认为它会起作用。

希望这会有所帮助,祝你好运!

+2

你是我的个人英雄。赏金是你和我的许多很多谢谢。 – 2011-06-20 05:00:34

+0

你很受欢迎。所以那工作? – walta 2011-06-20 18:00:40

+0

在创建新活动并从那里购买产品后,在购买产品后返回到我的andengine活动现在可以正常工作:D – Spider 2013-03-21 01:41:21