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);
}
});
}
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);
}
});
}
}
Aggregations