Search in sources :

Example 1 with IsEnvReadyResult

use of com.huawei.hms.iap.entity.IsEnvReadyResult in project Osmand by osmandapp.

the class IapRequestHelper method isEnvReady.

/**
 * To check whether the country or region of the logged in HUAWEI ID is included in the countries or regions supported by HUAWEI IAP.
 * @param mClient IapClient instance to call the isEnvReady API.
 * @param callback IapApiCallback.
 */
public static void isEnvReady(IapClient mClient, final IapApiCallback callback) {
    Log.i(TAG, "call isEnvReady");
    Task<IsEnvReadyResult> task = mClient.isEnvReady();
    task.addOnSuccessListener(new OnSuccessListener<IsEnvReadyResult>() {

        @Override
        public void onSuccess(IsEnvReadyResult result) {
            Log.i(TAG, "isEnvReady, success");
            callback.onSuccess(result);
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "isEnvReady, fail");
            callback.onFail(e);
        }
    });
}
Also used : OnSuccessListener(com.huawei.hmf.tasks.OnSuccessListener) OnFailureListener(com.huawei.hmf.tasks.OnFailureListener) IapApiException(com.huawei.hms.iap.IapApiException) IsEnvReadyResult(com.huawei.hms.iap.entity.IsEnvReadyResult)

Example 2 with IsEnvReadyResult

use of com.huawei.hms.iap.entity.IsEnvReadyResult in project Osmand by osmandapp.

the class InAppPurchaseHelperImpl method isInAppPurchaseSupported.

@Override
public void isInAppPurchaseSupported(@NonNull final Activity activity, @Nullable final InAppPurchaseInitCallback callback) {
    if (envReady) {
        if (callback != null) {
            if (purchaseSupported) {
                callback.onSuccess();
            } else {
                callback.onFail();
            }
        }
    } else {
        // Initiating an isEnvReady request when entering the app.
        // Check if the account service country supports IAP.
        IapClient mClient = Iap.getIapClient(activity);
        final WeakReference<Activity> activityRef = new WeakReference<>(activity);
        IapRequestHelper.isEnvReady(mClient, new IapApiCallback<IsEnvReadyResult>() {

            private void onReady(boolean succeed) {
                logDebug("Setup finished.");
                envReady = true;
                purchaseSupported = succeed;
                if (callback != null) {
                    if (succeed) {
                        callback.onSuccess();
                    } else {
                        callback.onFail();
                    }
                }
            }

            @Override
            public void onSuccess(IsEnvReadyResult result) {
                onReady(true);
            }

            @Override
            public void onFail(Exception e) {
                onReady(false);
                LOG.error("isEnvReady fail, " + e.getMessage(), e);
                ExceptionHandle.handle(activityRef.get(), e);
            }
        });
    }
}
Also used : IapClient(com.huawei.hms.iap.IapClient) WeakReference(java.lang.ref.WeakReference) Activity(android.app.Activity) ParseException(java.text.ParseException) IsEnvReadyResult(com.huawei.hms.iap.entity.IsEnvReadyResult)

Aggregations

IsEnvReadyResult (com.huawei.hms.iap.entity.IsEnvReadyResult)2 Activity (android.app.Activity)1 OnFailureListener (com.huawei.hmf.tasks.OnFailureListener)1 OnSuccessListener (com.huawei.hmf.tasks.OnSuccessListener)1 IapApiException (com.huawei.hms.iap.IapApiException)1 IapClient (com.huawei.hms.iap.IapClient)1 WeakReference (java.lang.ref.WeakReference)1 ParseException (java.text.ParseException)1