• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

Checking the Support for HUAWEI IAP

Search This thread

XDARoni

XDA Community Manager
Before using HUAWEI IAP on your app, send an isEnvReady request from your app to HUAWEI IAP to check whether the currently signed-in HUAWEI ID is located in a country or region where HUAWEI IAP is available.

If your app does not connect to the HUAWEI ID sign-in API, connect to this API to sign in.

Perform the following steps for your development:

Send an isEnvReady request and set two callback listeners to receive the request result.

● If the request result is Succeeded, your app will obtain an IsEnvReadyResult instance, indicating that the country or region where the currently signed-in HUAWEI ID is located supports HUAWEI IAP.

● If the request result is Failed, HUAWEI IAP will return an Exception object. If the object is IapApiException, use its getStatusCode() method to obtain the result code of the request.

If the result code is OrderStatusCode.ORDER_HWID_NOT_LOGIN (no HUAWEI ID signed in), use status in the IapApiException object to bring up the HUAWEI ID sign-in screen. Then, obtain the result in the onActivityResult method of Activity. Parse returnCode from the intent returned by onActivityResult. If returnCode is OrderStatusCode.SUCCESS, the country or region where the currently signed-in HUAWEI ID is located supports HUAWEI IAP. If returnCode is not OrderStatusCode.SUCCESS, an exception occurs.
Code:
// To get the Activity instance that calls this API.
Activity activity = getActivity();
Task<IsEnvReadyResult> task = Iap.getIapClient(activity).isEnvReady();
task.addOnSuccessListener(new OnSuccessListener<IsEnvReadyResult>() {
    @Override
    public void onSuccess(IsEnvReadyResult result) {
        // Obtain the execution result.
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(Exception e) {
        if (e instanceof IapApiException) {
            IapApiException apiException = (IapApiException) e;
            Status status = apiException.getStatus();
            if (status.getStatusCode() == OrderStatusCode.ORDER_HWID_NOT_LOGIN) {
                // Not logged in.
                if (status.hasResolution()) {
                    try {
                        // 6666 is an int constant defined by the developer.
                        status.startResolutionForResult(getActivity(), 6666);
                    } catch (IntentSender.SendIntentException exp) {
                    }
                }
            } else if (status.getStatusCode() == OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED) {
                // The current region does not support HUAWEI IAP.
            }
        }
    }
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 6666) {
        if (data != null) {
            // Obtain the execution result.
            int returnCode = data.getIntExtra("returnCode", 1);
        }
    }
}