感谢您访问我的页面。
几天前,我用app-billing开发了简单的安卓游戏。
现在我将实施恢复购买功能,但我不知道如何点对它。
我已经进行了几天的谷歌搜索,发现了许多链接来帮助它,但他们现在没有工作。
请以编程方式告诉我如何操作。
我在哪里可以找到恢复购买的样本?
我已经实施了应用内购买但未恢复购买。
我使用的是Android Studio 1.5.1。
我已提到http://www.techotopia.com/index.php/An_Android_Studio_Google_Play_In-app_Billing_Tutorial在应用购买中实施。
请帮帮我:(
提前致谢。
答案 0 :(得分:5)
如果您使用v3实施InApp购买,则无需担心还原购买实施。您可以查询库存并捕获现有的购买信息。请检查实施情况。
我在这里做的是我已经购买了一个模块。当我完成购买时,我会将信息发送到我们的服务器。在重新登录或返回应用程序后,服务器将发送当前用户购买信息,无论他是否已购买。如果服务器给出否定结果,我将检查那里有任何现有购买的查询库存。为此,我在MainActivity onCreate()中使用以下代码。
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
Log.e(TAG, "In App Set UP error:: Please check gmail account settings/ Credit Card Info etc");
return;
}
if (mHelper == null) return;
mBroadcastReceiver = new IabBroadcastReceiver(MainActivity.this);
IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
registerReceiver(mBroadcastReceiver, broadcastFilter);
Log.d(TAG, "Setup successful. Querying inventory.");
if (mSupplier.getmSubscriptionStatus() == 0) { // This is the Status given from Local Server 0- UnScubscribed User, 1- Subscribed User
mHelper.queryInventoryAsync(mGotInventoryListenerForPurchase);
}
}
});
在结果中,您可以识别现有的购买信息。
IabHelper.QueryInventoryFinishedListener mGotInventoryListenerForPurchase = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
try {
Log.d(TAG, "Query inventory For Purchase finished.");
String payload = // Your developer payload
if (mHelper == null) return;
if (result.isFailure()) {
Log.v(TAG, "PURCHSE RESULT ERROR- NO PURCHASE AVAILABLE");
return;
}
Log.v(TAG, "Query inventory For Purchase was successful.");
if (mSkuDetailList == null || mSkuDetailList.isEmpty()) {
Log.v(TAG, "SKU INFO FROM LOCAL SERVER- UNABLE TO PURCHASE");
return;
}
Purchase premiumPurchase = null;
for (IabSkuDetailModel data : mSkuDetailList) {
// Filter the purchase info using SKU:::
premiumPurchase = inventory.getPurchase(data.getmPackageName());
if (premiumPurchase != null) {
break;
}
}
if (premiumPurchase == null) {
Log.v(TAG, "NO Available Purchase for this user");
return;
}
if (verifyDeveloperPayload(premiumPurchase)) {
Log.v(TAG, "Purchase is there already ::: developer payload is Matching:: This need to update Local Server: No need to purchase agian");
if (premiumPurchase.getSku().equalsIgnoreCase(mSelectedSku)) {
IabPurchaseUpdateReq request = new IabPurchaseUpdateReq();
request.setmPurchaseToken(premiumPurchase.getToken());
request.setmUserId("" + mSupplier.getmUserId());
request.setmPublicKey(IabConstants.IAB_RSA_PUBLIC_KEY);
request.setmSignature(premiumPurchase.getSignature());
request.setmSubscriptionId(premiumPurchase.getSku());
request.setmPurchaseObj(premiumPurchase.getOriginalJson());
//Update "result to local Server"
} else {
Log.v(TAG, "SKU mismatch ::: ");
}
} else {
Log.v(TAG, "Developer payload error:: Wrong Purchase");
}
} catch (Exception e) {
e.printStackTrace();
}
}
};