我有一个生活中的应用程序,当我买东西时没有任何事情发生!然后当我第二次点击它时,它会调用监听器, result.isSuccess 总是为假!请帮忙。
我似乎无法找到解决方案。我的onActivityResult设置正确。 Google Play称购买完成。一切都相应,但我的听众从不执行代码。我确信这是一个简单的修复,我只是忽略了它。
检查result.isSuccessful() - >评估代码。你第一次购买它......没有任何反应。 else语句未被调用。未调用成功声明。第二次按下按钮购买项目时,它会调用相应监听器中的else语句。我非常想要一条错误消息,但没有抛出任何错误。唔...
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_store, container, false);
removeAdsOnly = (Button)view.findViewById(R.id.store_ads_btn);
removeAdsOnly.setOnClickListener(this);
mHelper = new IabHelper(getContext(), base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if(!result.isSuccess()){
Log.d(AppUtils.APP_NAME, "In-App Billing setup failed: " + result);
Toast.makeText(getContext(), "Failed to setup in-app billing.", Toast.LENGTH_LONG).show();
} else {
Log.d(AppUtils.APP_NAME, "In-App Billing setup is OK");
}
}
});
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Store.this.getActivity().getBaseContext());
boolean adsPurchased = prefs.getBoolean("purchasedAds", false);
if(adsPurchased){
removeAdsOnly.setClickable(false);
removeAdsOnly.setAlpha(0.5f);
}
return view;
}
@Override
public void onClick(View v) {
int id = v.getId();
//TODO: Uncomment StartAppSDK.inAppPurchaseMade Upon Release
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Store.this.getActivity().getBaseContext());
boolean adsPurchased = prefs.getBoolean("purchasedAds", false);
if(id == removeAdsOnly.getId()){
if(!adsPurchased){
mHelper.launchPurchaseFlow(Store.this.getActivity(), ADSPACK_SKU, 10001, adsPuchaseListener);
//StartAppSDK.inAppPurchaseMade(getContext(), 0.99);
if(developerStore){
SharedPreferences.Editor edit = prefs.edit();
edit.putBoolean("purchasedAds", Boolean.TRUE);
edit.commit();
}
} else {
Toast.makeText(getContext(), "Looks like you have already purchased this item.", Toast.LENGTH_LONG).show();
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(AppUtils.APP_NAME, "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 {
Log.d(AppUtils.APP_NAME, "onActivityResult handled by IABUtil.");
}
}
IabHelper.OnIabPurchaseFinishedListener adsPuchaseListener = new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if(result.isSuccess()){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Store.this.getActivity().getBaseContext());
SharedPreferences.Editor edit = prefs.edit();
edit.putBoolean("purchasedAds", Boolean.TRUE);
edit.commit();
removeAdsOnly.setClickable(false);
removeAdsOnly.setAlpha(0.5f);
} else {
Toast.makeText(getContext(), "Failed to purchase Ad Removal.", Toast.LENGTH_LONG).show();
return;
}
}
};