好的,所以我一直试图解决这个问题好几天,而且我不会来这里寻找别人为我工作,因为我一直在排除故障并修复了LogCat中的每一条错误消息。我正在使用Andengine开发Android游戏(这可能是问题的一部分,因此熟悉它可能有所帮助)。我没有做任何太花哨的事情,我的游戏活动都是单一的场景,没有任何物理或类似的东西,只是一堆精灵和纹理。我还使用Andengine进行游戏中的所有其他活动,因为我觉得这是一种非常简单的方法来设置图形吸引人的屏幕。一个这样的屏幕是我的应用程序商店,用户可以购买levelpacks和新的精灵。这一切的计费部分都很有效,购买通过市场,那里没什么太复杂的......
当用户点击购买时,弹出市场屏幕并加载他们选择的产品(这些是真实产品,而不是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()方法。我从我的StoreFront活动中调用请求购买,如下所示:
BillingHelper.requestPurchase(StoreFront.this, itemID);
并且在StoreFront的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
}
};
};
所以我不认为那里存在问题。以下是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.
此外,我已经在另一部手机上测试了这个(我正在使用的另一位开发人员,实际上可以在其中购买但仍会出现黑屏错误)并且他从未收到您在评论中提到的处理程序消息
编辑:如果我不得不猜测错误在哪里,我会说这是
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库需要中断的异常,因此这是一个红色的鲱鱼。
另外(我希望这是允许的)我会为解决方案提供paypal奖励。如果这违反了SO的条款,那么只需删除此行,请不要关闭此问题。
答案 0 :(得分:5)
我可能知道什么是错的,我有一个测试你要做。在用户取消购买或完成购买后,购买屏幕将执行完成呼叫。对于我来说,由于某种原因,结束通话正在进入当前正在运行的活动中并且(关闭它)。
以下是日志中的相关行:
06-16 11:20:22.774:WARN / ActivityManager(132):对HistoryRecord {40ace828 com.android.vending / .billing.InAppBuyPageActivity}的重复完成请求
我想我在我的代码问题中解决了这个问题,我不记得我做了什么(可能没有在我的购买完整处理程序中调用完成...)
我对Andgen一无所知,但如果在主要的Andgen活动中调用完成后会发生什么?我想它会停止执行,你可能会出现黑屏和应用程序崩溃。
因此,要测试此项,请为您购买页面创建单独的活动。不需要复杂 - 也许它只是在它启动后购买一个罐头产品。运行你的代码,看它是否仍然给你黑屏厄运。我敢打赌:它可能退出游戏回到你的游戏,但我认为它会起作用。
希望这会有所帮助,祝你好运!