Search in sources :

Example 1 with IapClient

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

the class IapRequestHelper method showSubscription.

/**
 * link to subscription manager page
 * @param activity activity
 * @param productId the productId of the subscription product
 */
public static void showSubscription(final Activity activity, String productId) {
    StartIapActivityReq req = new StartIapActivityReq();
    if (TextUtils.isEmpty(productId)) {
        req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY);
    } else {
        req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY);
        req.setSubscribeProductId(productId);
    }
    IapClient iapClient = Iap.getIapClient(activity);
    Task<StartIapActivityResult> task = iapClient.startIapActivity(req);
    task.addOnSuccessListener(new OnSuccessListener<StartIapActivityResult>() {

        @Override
        public void onSuccess(StartIapActivityResult result) {
            if (result != null) {
                result.startActivity(activity);
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            ExceptionHandle.handle(activity, e);
        }
    });
}
Also used : IapClient(com.huawei.hms.iap.IapClient) StartIapActivityReq(com.huawei.hms.iap.entity.StartIapActivityReq) StartIapActivityResult(com.huawei.hms.iap.entity.StartIapActivityResult) OnSuccessListener(com.huawei.hmf.tasks.OnSuccessListener) OnFailureListener(com.huawei.hmf.tasks.OnFailureListener) IapApiException(com.huawei.hms.iap.IapApiException)

Example 2 with IapClient

use of com.huawei.hms.iap.IapClient 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

IapClient (com.huawei.hms.iap.IapClient)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 IsEnvReadyResult (com.huawei.hms.iap.entity.IsEnvReadyResult)1 StartIapActivityReq (com.huawei.hms.iap.entity.StartIapActivityReq)1 StartIapActivityResult (com.huawei.hms.iap.entity.StartIapActivityResult)1 WeakReference (java.lang.ref.WeakReference)1 ParseException (java.text.ParseException)1