Skip to content

Commit

Permalink
Fixed Exceptions in case of unavailability of Google Billing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeisfeld committed Jul 23, 2017
1 parent 3236815 commit fb8e218
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

Expand Down Expand Up @@ -141,19 +142,22 @@ public void onDialogNegativeClick(final DialogFragment dialog) {
checkUnlockerApp();

// Check in-app purchases
GoogleBillingHelper.initialize(this, new OnInventoryFinishedListener() {

@Override
public void handleProducts(final List<PurchasedSku> purchases, final List<SkuDetails> availableProducts,
final boolean isPremium) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, isPremium);
if (isPremium) {
invalidateOptionsMenu();
try {
GoogleBillingHelper.initialize(this, new OnInventoryFinishedListener() {
@Override
public void handleProducts(final List<PurchasedSku> purchases, final List<SkuDetails> availableProducts,
final boolean isPremium) {
PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_has_premium_pack, isPremium);
if (isPremium) {
invalidateOptionsMenu();
}
GoogleBillingHelper.dispose();
}
GoogleBillingHelper.dispose();
}
});

});
}
catch (Exception e) {
Log.e(Application.TAG, "Failed to call Google Billing Helper", e);
}
}
}
}
Expand Down Expand Up @@ -230,7 +234,20 @@ else if (itemId == R.id.action_camera) {
}
else if (itemId == R.id.action_purchase) {
DialogUtil.displayToast(this, R.string.message_dialog_triggering_purchase);
triggerDefaultPurchase();
try {
triggerDefaultPurchase();
}
catch (Exception e) {
Log.e(Application.TAG, "Failed to call Google Billing Helper", e);
Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW);
googlePlayIntent.setData(Uri.parse("market://details?id=de.jeisfeld.augendiagnoseunlocker"));
try {
startActivity(googlePlayIntent);
}
catch (Exception e1) {
DialogUtil.displayError(this, R.string.message_dialog_failed_to_open_google_play, false);
}
}
return true;
}
else if (itemId == R.id.action_rating) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,12 @@ else if (mType.equals(getActivity().getString(R.string.key_dummy_screen_premium_
* Initialize Google Billing (after having permission).
*/
public final void initializeGoogleBilling() {
GoogleBillingHelper.initialize(getActivity(), mOnInventoryFinishedListener);
try {
GoogleBillingHelper.initialize(getActivity(), mOnInventoryFinishedListener);
}
catch (Exception e) {
android.util.Log.e(Application.TAG, "Failed to call Google Billing Helper", e);
}
}

/**
Expand Down

0 comments on commit fb8e218

Please sign in to comment.