Я показываю DialogFragment из действия и хочу выполнить какое-то действие по нажатию кнопки, но мой метод onActivityResult никогда не вызывался во фрагменте.
mHelper.launchPurchaseFlow(activity, itemForPurchase, 10001,mPurchaseFinishedListener, payload);
вышеуказанная функция работает нормально, и мой платеж также успешен, нопри повторном открытии приложения оно будет потреблять сумму.
public class InstantDealPopup extends DialogFragment implements OnClickListener {
private static IabHelper mHelper;
private static final int ID_IV_CLOSE = 1;
private static final int ID_IV_ACCEPT_BUY = 2;
private static final int ID_IV_REJECT_BUY = 3;
private static Activity activity;
private static SharedPreferences prefs;
private static SharedPreferences.Editor prefEditor;
private static String itemForPurchase;
private static int item;
private static int credit_amount = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, R.style.FragmentTheme);
initInApp();
setCancelable(false);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("onActivityResult(" + requestCode + "," + resultCode
+ "," + data);
// Pass on the activity result to the helper for handling
if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {
// not handled, so handle it ourselves (here's where you'd
// perform any handling of activity results not related to in-app
// billing...
super.onActivityResult(requestCode, resultCode, data);
} else {
System.out.println("onActivityResult handled by IABUtil.");
}
}
@Override
public void onClick(View v) {
if (v.getId() == ID_IV_BG || v.getId() == ID_IV_ACCEPT_BUY) {
if (!Utilities.isOnline(activity)) {
return;
}
itemForPurchase = chipsIds[dealIndex];
item = dealIndex;
inAppPurchase();
dismissAllowingStateLoss();
} else if (v.getId() == ID_IV_CLOSE || v.getId() == ID_IV_REJECT_BUY) {
dismissAllowingStateLoss();
}
}
public void inAppPurchase() {
if (mHelper == null)
return;
if (!mHelper.isSetupDone() && !mHelper.isAsyncInProgress()) {
return;
}
//Utilities.setWaitScreen(activity, true);
String payload = "";
try {
mHelper.launchPurchaseFlow(activity, itemForPurchase, 10001,
mPurchaseFinishedListener, payload);
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
}
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper
.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
//Utilities.setWaitScreen(activity, false);
return;
}
consumeItem(purchase);
}
};
public void consumeItem(Purchase purchase) {
if (mHelper == null)
return;
if (!mHelper.isSetupDone() && !mHelper.isAsyncInProgress()) {
return;
}
try {
mHelper.consumeAsync(purchase, mConsumeFinishedListener);
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
}
}
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper
.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (mHelper == null)
return;
if (result.isSuccess()) {
if (purchase.getSku().equals(itemForPurchase)) {
if (buyer) {
ReceiptVarifier.getInstance(activity).verifyReceipt(purchase
.getSignature(),
purchase.getOriginalJson(), purchase.getOrderId(), "" +
(buyerCreditValue[item]*credit_amount),
"" + buyCreditPrice[item]);
} else if (!buyer) {
ReceiptVarifier.getInstance(activity).verifyReceipt(purchase
.getSignature(),
purchase.getOriginalJson(), purchase.getOrderId(), "" +
(nonBuyerCreditValue[item]*credit_amount),
"" + buyCreditPrice[item]);
}
}
} else {
System.out.println("Error While Consuming.....");
Utilities.setWaitScreen(activity, false);
Toast.makeText(
activity,
"Please Check internet connectivity and restart buy chips screen to get " +
"amount!!!",
Toast.LENGTH_LONG).show();
}
}
};
private void initInApp() {
mHelper = new IabHelper(activity, base64EncodedPublicKey);
mHelper.enableDebugLogging(true);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d("In-app Billing", "In-app Billing setup failed: " + result);
} else {
Log.d("In-app Billing", "In-app Billing is set up OK");
if (mHelper == null)
return;
try {
mHelper.queryInventoryAsync(mGotInventoryListener);
} catch (IabHelper.IabAsyncInProgressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper
.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null)
return;
if (result.isFailure()) {
return;
}
Log.d(TAG, "Query inventory was successful.");
for (int i = chipsIds.length-1; i >= 0; i--) {
Purchase purchase = inventory.getPurchase(chipsIds[i]);
System.out.println("purchase : " + purchase);
if (purchase != null) {
Log.d(TAG, "We have previous product. Consuming it.");
itemForPurchase = chipsIds[i];
item = i;
Utilities.setWaitScreen(activity, true);
consumeItem(purchase);
return;
}
}
}
};
@Override
public void onDestroyView() {
if (getView() != null) {
Utilities.unbindDrawables(getView());
}
super.onDestroyView();
}
}