huawei-mobile-serviceshuawei-developershuawei-iap

Migration from Google Play Store to Huawei Store. Any changes in code?


I have an application live in Google Play Store. I am planning to publish it also in Huawei Store.

Apart from re-building the app with the Huawei SDK and the basic instructed steps (Add into the project agconnect-services.json etc..), is there something else that needs to be changed at code level ?

Are all APIs working ? Specially those related to in-app purchases ?

Thanks


Solution

  • First, please check out what GMS Kit you are using, and I could provide you corresponding HMS Kits. You can refer to this answer as well.

    At code level, if you want to:

    1. Use G2H solution: replace GMS code with HMS code directly. Although the name of HMS interface is different from GMS interface, the meaning of the interfaces is the same. You could just change the interface name by referring to the API documentation.
    2. Use G+H solution: HMS+GMS adaptation layer code is added to the original logic code. Add the following code to determine whether GMS APIs or HMS APIs are available and call the available APIs:
    public boolean  isGMS(){
        return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == com.google.android.gms.common.ConnectionResult.SUCCESS;
    }
    public boolean  isHMS(){
        return HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(this) == com.huawei.hms.api.ConnectionResult.SUCCESS;
    }
    

    The logic of the code invoking:

    If ( isGMS() ) {
    //GMS code
    }else if ( isHMS() ){
    //HMS code
    }
    

    HMS provides interfaces similar to those of the GMS. Here are IAP documentation and Github.

    You can also use HMS ToolKit to implement G2H/G+H.

    Update:

    You can use the following code to obtain productId:

    PurchaseResultInfo buyResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data); 
    

    The getInAppPurchaseData() method is called through the buyResultInfo object declared by PurchaseResultInfo. You can obtain InAppPurchaseData after the getInAppPurchaseData method is successfully called.

    The product ID of the current transaction is stored in InAppPurchaseData. See: here.

    IAPdata