在App Billing中,有待定意图和切换活动。

| 好的,所以我已经尝试了好几天,并且我来这里不是为了寻找我的工作,而是因为我一直在进行故障排除并修复了LogCat中的每条错误消息。我正在使用Andengine开发Android游戏(这可能是问题的一部分,因此熟悉它可能会有所帮助)。我并没有做任何花哨的事情,我的游戏活动都是单一场景,没有任何物理或类似的东西,只有一堆精灵和纹理。我还使用Andengine进行游戏中的所有其他活动,因为我发现它是设置具有图形吸引力的屏幕的一种非常简单的方法。我的应用程序内商店就是这样一个屏幕,用户可以在其中购买关卡包和新的精灵。这一切的计费部分都很好,购买进入市场,那里没有什么太复杂的... 当用户单击“购买”时,将弹出市场屏幕并加载他们选择的产品(这些是真实产品,尽管游戏未发布,但不是android测试)。无论我是在游戏堆栈的一部分中使用“ Android 2.0”实现,还是在其中使用“ Android 1.6”实现,都将在当前活动上方弹出“市场”屏幕。它自己的堆栈。我更喜欢使用Android 2.0实现,但是如果我只能使1.6正常运行,我会接受的。因此,无论如何,当用户使用“后退”按钮取消购买交易或使用信用卡完成购买交易时,都会出现问题,这都会导致市场屏幕消失,并且应用程序开始一个只是黑屏的新活动(最终会并导致力量闭合)。购买通过OK,但用户未获得产品,因为在我们获得更改游戏中用户物品的代码之前,游戏已经退出。现在,对于一些代码,我使用了本教程(http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html),而无需进行任何更改。 BillingHelper类最为重要,因为它包含requestPurchase()方法和startBuyPageActivity()方法。我通过这样的StoreFront活动致电请求购买:
            BillingHelper.requestPurchase(StoreFront.this, itemID); 
在StoreFront的onCreate中,我有这个东西(如tut所说):
        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
        }
    };

};
因此,我认为问题不存在于此。这是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());
    }
}
我试过从StoreFront调用带有各种参数的“ ActivityContext \”,例如StoreFront.this,getApplicationContext(),其他位置的静态上下文存储,其他位置的静态Activity,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\");
    }
}
没什么好想的,我只希望用户在购买商品或在此过程中按回去时,可以回到我的各种活动中(最好是StoreFront)。请帮助! 编辑:我希望任何可能的解决方案,包括购买完成后,允许应用程序内结算在购买完成后返回我的应用程序。 编辑 一个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. 
另外,我已经在另一部手机上测试了这一点(与我合作的另一位开发人员,可以在其中购买东西,但仍然出现黑屏错误),而且他也从未收到您在评论中提到的Handler消息。 编辑:如果我不得不猜测错误在哪里,我会说是这个
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条款》,请删除此行,请不要关闭此问题。     
已邀请:
我可能知道出了什么问题,我有一个测试要教您。在用户取消购买或完成购买之后,购买屏幕将运行结束呼叫。对我来说,由于某种原因,结束调用正在移至当前正在运行的活动中(并关闭)。 这是日志中的相关行: 06-16 11:20:22.774:WARN / ActivityManager(132):HistoryRecord的重复完成请求{40ace828 com.android.vending / .billing.InAppBuyPageActivity} 我想我在代码问题中解决了这个问题,因为我不记得自己到底做了什么(也许没有在我的购买完成处理程序中调用finish。) 我对Andgen一无所知,但是如果在主要的Andgen活动上打完电话会怎样?我以为它将停止执行,并且您可能会出现黑屏和应用程序崩溃的情况。 因此,要对此进行测试,请为您的购买页面创建一个单独的活动。不需要太复杂-也许在启动后只购买一种罐头产品即可。运行您的代码,看看它是否仍然给您带来厄运的黑屏。我敢打赌:它可能会从活动中退出,重新回到您的游戏中,但我认为它会起作用。 希望这会有所帮助,祝你好运!     

要回复问题请先登录注册