ahmad naeem ahmad naeem - 1 month ago 10
Android Question

In App Billing crashed in API 23

I am Upgrading my project to API 23. My App is crashed on In-App Billing with API 23 but its works on API 22. When purchasehandler calls the PurchaseItem method, the app is crash on launchPurchaseFlow method.

--------- beginning of crash
10-26 13:24:12.048 3031-3031/com.example.--- E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.---, PID: 3031
java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: launchPurchaseFlow
at com.android.vending.billing.util.IabHelper.checkSetupDone(IabHelper.java:790)
at com.android.vending.billing.util.IabHelper.launchPurchaseFlow(IabHelper.java:380)
at com.MyQalam.InappPurchase.InappPurchaseHandler.PurchaseItem(InappPurchaseHandler.java:31)
at com.MyQalam.ShalatIndonesian.IndexActivity.onMenuItemSelected(IndexActivity.java:95)
at com.android.internal.policy.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1151)
at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:468)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:129)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)


Here is my Code:

private Context mContext;
private IabHelper billinHelper;
public InappPurchaseHandler(Context context) {
this.mContext = context;
billinHelper = new IabHelper(context, AppPropertyKey.BASE_64_KEY);
Toast.makeText(context.getApplicationContext(),"IABHEPLER",Toast.LENGTH_SHORT).show();

}

public void setonsetupCompleteListener(IabHelper.OnIabSetupFinishedListener listener){
billinHelper.startSetup(listener);
}


public void OnItemInventoryAsyn(IabHelper.QueryInventoryFinishedListener listener){

billinHelper.queryInventoryAsync(listener);
}
public void PurchaseItem(String sku,IabHelper.OnIabPurchaseFinishedListener listener){
//if(billinHelper.isSetupDone() && !billinHelper.isAsyncInProgress())//change
if (billinHelper!=null)
billinHelper.launchPurchaseFlow((Activity) mContext, sku, IabHelper.ITEM_TYPE_SUBS, 123, listener, "");
}


public void OnBillingActivityResult(int requestCode,int resultCode,Intent data){
billinHelper.handleActivityResult(requestCode, resultCode, data);
}
public void disposeBillingHelper() {
if (billinHelper != null) {
billinHelper.dispose();
}
billinHelper = null;
}


Here is the code where i call the function:

purchaseHandler.PurchaseItem(RemoveAds.SKU,
new OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result,
Purchase info) {
if (result.isSuccess()) {
dataManager.setRemoveAds(true);
Toast.makeText(IndexActivity.this,
"Ads Successfully Removed.",
Toast.LENGTH_LONG).show();
RefrshActivity();
}
}
});

Answer

That the solution man:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

            purchaseHandler.OnBillingActivityResult(requestCode,resultCode,data));
}
Comments