このチュートリアルからアプリ内課金を実装しました。購入するアイテムは、カスタム背景を設定する機能です。うまく機能しますが、アプリをアンインストールして再インストールする(またはユーザー設定をクリアする)と、誰かがアプリ内アイテムを既に購入していることを確認する方法がわかりません。
public void buySelected() {
if (backgroundColorsPurchased == true) {
this.colorChangeDialog(); //if user has already purchased, just call the dialog instead of re-buying.
//if the person has cleared their prefs, they'll have to be online to re-verify that they did indeed buy the item.
}else{
if(BillingHelper.isBillingSupported()){
BillingHelper.requestPurchase(mContext, "background.colors");
BillingHelper.setCompletedHandler(mTransactionHandler);
} else {
Log.i(TAG,"Can't purchase on this device");
}
}
}
次に、ハンドラーがあります。
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()){
//this is where we show the stuff that the person purchased. In this case, the dialog to change the background colour.
backgroundColorsPurchased = true; //just setting this to true so that the next time somebody clicks the donate button it'll just open the dialog.
//call the change background dialog
colorChangeDialog();
}else{
//fail
Toast.makeText(getApplicationContext(), "Fail", Toast.LENGTH_SHORT).show();
}
}
};
アイテムが以前に購入されたことを確認するにはどうすればよいですか?マーケットは、「このアイテムをすでに購入したか、購入がまだ保留中です」というダイアログウィンドウを表示し続けます。if(BillingHelper.latestPurchase.isPurchased()){
ハンドラー内にない場合、フォースを閉じるようなものを使用しようとすると。