diff options
author | Nuno Santos <nunosantos@imaginando.net> | 2017-10-01 16:26:47 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-10-19 06:36:34 +0000 |
commit | f9378f6f03e8f565e2d080b339ed8d68d22054a0 (patch) | |
tree | 714228e4c5adde2ef878f754cfb2f747669448e2 | |
parent | 3b4079f9c20e1c33b565b90fc51c05667ebdf421 (diff) |
Android: More informative error string in some casesv5.10.0-beta3
Some devices will fail synchronously when trying to create
the buy intent, instead of calling handleActivityResult()
with the result.
When trying to purchase an item already owned by the user
on a such device, you would get a purchase failed signal
with a very generic error string, as we assumed this could
only be caused by a system error. This patch improves the
error message by including a description of the response code
in the cases where the system returns something usable here.
[ChangeLog][Android] Added more informative error messages when
the purchasing subsystem was unable to create the buy intent.
Task-number: QTBUG-57700
Change-Id: I6328b38b33edf4c1c53d2465bf2205c970bf7e78
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java | 18 | ||||
-rw-r--r-- | src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp | 18 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java b/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java index 002e94b..94bc202 100644 --- a/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java +++ b/src/android/src/org/qtproject/qt5/android/purchasing/QtInAppPurchase.java @@ -374,7 +374,7 @@ public class QtInAppPurchase m_publicKey = publicKey; } - public IntentSender createBuyIntentSender(String identifier) + public IntentSender createBuyIntentSender(String identifier, int requestCode) { if (m_service == null) { Log.e(TAG, "Unable to create buy intent. No IAP service connection."); @@ -388,9 +388,21 @@ public class QtInAppPurchase TYPE_INAPP, identifier); int response = bundleResponseCode(purchaseBundle); + if (response != RESULT_OK) { - Log.e(TAG, "Unable to create buy intent. Response code: " + response); - return null; + Log.e(TAG, "Unable to create buy intent. Response code: " + response); + String errorString; + switch (response) { + case RESULT_BILLING_UNAVAILABLE: errorString = "Billing unavailable"; break; + case RESULT_ITEM_UNAVAILABLE: errorString = "Item unavailable"; break; + case RESULT_DEVELOPER_ERROR: errorString = "Developer error"; break; + case RESULT_ERROR: errorString = "Fatal error occurred"; break; + case RESULT_ITEM_ALREADY_OWNED: errorString = "Item already owned"; break; + default: errorString = "Unknown billing error " + response; break; + }; + + purchaseFailed(requestCode, FAILUREREASON_ERROR, errorString); + return null; } PendingIntent pendingIntent = purchaseBundle.getParcelable("BUY_INTENT"); diff --git a/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp b/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp index e6a42cb..ee00591 100644 --- a/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp +++ b/src/purchasing/inapppurchase/android/qandroidinapppurchasebackend.cpp @@ -334,14 +334,6 @@ void QAndroidInAppPurchaseBackend::purchaseProduct(QAndroidInAppProduct *product return; } - QAndroidJniObject intentSender = m_javaObject.callObjectMethod("createBuyIntentSender", - "(Ljava/lang/String;)Landroid/content/IntentSender;", - QAndroidJniObject::fromString(product->identifier()).object<jstring>()); - if (!intentSender.isValid()) { - purchaseFailed(product, QInAppTransaction::ErrorOccurred, QStringLiteral("Unable to get intent sender from service")); - return; - } - int requestCode = 0; while (m_activePurchaseRequests.contains(requestCode)) { requestCode++; @@ -352,6 +344,16 @@ void QAndroidInAppPurchaseBackend::purchaseProduct(QAndroidInAppProduct *product } m_activePurchaseRequests[requestCode] = product; + + QAndroidJniObject intentSender = m_javaObject.callObjectMethod("createBuyIntentSender", + "(Ljava/lang/String;I)Landroid/content/IntentSender;", + QAndroidJniObject::fromString(product->identifier()).object<jstring>(), requestCode); + + if (!intentSender.isValid()) { + m_activePurchaseRequests.remove(requestCode); + return; + } + QtAndroid::startIntentSender(intentSender, requestCode, this); } |