Java IInapplingService卡在采购覆盖中
我没有购买,我用Java IInapplingService卡在采购覆盖中,java,android,in-app-purchase,android-inapp-purchase,Java,Android,In App Purchase,Android Inapp Purchase,我没有购买,我用 mService = IInAppBillingService.Stub.asInterface(service); 并用 Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); serviceIntent.setPackage("com.android.vending"); contex
mService = IInAppBillingService.Stub.asInterface(service);
并用
Intent serviceIntent =
new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
context.bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
然后,我开始购买
JSONObject jsonObject = new JSONObject();
jsonObject.put("android_id", MainApplication.getInstance().android_id);
jsonObject.put("user_id", userId);
jsonObject.put("email", userEmail);
Bundle buyIntentBundle = mService.getBuyIntent(3, context.getPackageName(),
purchasingItemId, "inapp", jsonObject.toString());
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
if (pendingIntent != null) {
fragmentActivity.startIntentSenderForResult(pendingIntent.getIntentSender(),
MainApplication.ACTIVITY_RESULT_REQUEST_KEY.IN_APP_BILLING_PURHASING_RESPONSE,
new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
}
它工作正常,我看到带有预加载程序的白卡-然后是购买信息,单击确定
,再次看到带有预加载程序的白卡,然后是带有购买成功
的白卡,但如果我在看到购买信息或购买成功
(当预加载程序旋转时)然后再打开它-我看到无限预加载,什么也没发生,后退按钮不起作用(但购买成功,用户在后台得到他的物品),唯一的办法是重新启动应用程序
这就是它的样子-
为什么会发生这种情况以及如何避免这种情况?这里有一个可能的解决方案: 在应用程序购买控制器中添加一个标志,用于启动应用程序内购买意图
public volatile boolean inAppFragmentOpened = false;
在发送意向之前将其设置为true
,在购买结束时将其设置为false
然后,在Activity
的方法onStart()
中添加此检查
if (InAppBillingFacade.getInstance().inAppFragmentOpened) {
InAppBillingFacade.getInstance().inAppFragmentOpened = false;
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
如果启动时出现打开的“应用内购买”窗口,这将重新启动您的应用程序-这有助于避免出现故障和冻结,但可能有人知道更好的解决方案?这里有一个可能的解决方案: 在应用程序购买控制器中添加一个标志,用于启动应用程序内购买意图
public volatile boolean inAppFragmentOpened = false;
在发送意向之前将其设置为true
,在购买结束时将其设置为false
然后,在Activity
的方法onStart()
中添加此检查
if (InAppBillingFacade.getInstance().inAppFragmentOpened) {
InAppBillingFacade.getInstance().inAppFragmentOpened = false;
Intent i = new Intent(this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
如果启动时出现打开的应用程序内购买
窗口,这将重新启动您的应用程序-这有助于避免出现故障和冻结,但可能有人知道更好的解决方案