问题
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
回答1:
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:
- 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.
- 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.
回答2:
@shirley, yes I actually found it also.
The following code works well in Cloud Debugging in all devices, but it doesn't work for review. Therefore the app is rejected.
Inside activity class:
private IapClient mIAPClient;
On activity creation:
mIAPClient = Iap.getIapClient(this);
When a user clicks the button that triggers the in-app purchase:
private void launchPurchase(String purchased_sku) {
IapRequestHelper.createPurchaseIntent(mIAPClient, purchased_sku, IapClient.PriceType.IN_APP_NONCONSUMABLE, new IapApiCallback<PurchaseIntentResult>() {
@Override
public void onSuccess(PurchaseIntentResult result) {
if (result == null) {
Log.e(Constants.TAG, "result is null");
return;
}
// you should pull up the page to complete the payment process
IapRequestHelper.startResolutionForResult(StoreActivity.this, result.getStatus(), Constants.REQ_CODE_BUY);
}
@Override
public void onFail(Exception e) {
int errorCode = ExceptionHandle.handle(StoreActivity.this, e);
if (errorCode != ExceptionHandle.SOLVED) {
Log.i(Constants.TAG, "createPurchaseIntent, returnCode: " + errorCode);
// handle error scenarios
switch (errorCode) {
case OrderStatusCode.ORDER_PRODUCT_OWNED:
Log.i(Constants.TAG, "createPurchaseIntent, returned ORDER_PRODUCT_OWNED");
break;
default:
break;
}
}
}
});
}
The above catches an exception onFail(Exception e). While trying to get the errorCode from ExceptionHandle I get nothing.
public static int handle(Activity activity, Exception e) {
if (e instanceof IapApiException) {
IapApiException iapApiException = (IapApiException) e;
Log.i(TAG, "returnCode: " + iapApiException.getStatusCode());
switch (iapApiException.getStatusCode()) {
case OrderStatusCode.ORDER_STATE_CANCEL:
Toast.makeText(activity, "Order has been canceled!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_STATE_PARAM_ERROR:
Toast.makeText(activity, "Order state param error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_STATE_NET_ERROR:
Toast.makeText(activity, "Order state net error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_VR_UNINSTALL_ERROR:
Toast.makeText(activity, "Order vr uninstall error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_HWID_NOT_LOGIN:
IapRequestHelper.startResolutionForResult(activity, iapApiException.getStatus(), Constants.REQ_CODE_LOGIN);
return SOLVED;
case OrderStatusCode.ORDER_PRODUCT_OWNED:
Toast.makeText(activity, "Product already owned error!", Toast.LENGTH_SHORT).show();
return OrderStatusCode.ORDER_PRODUCT_OWNED;
case OrderStatusCode.ORDER_PRODUCT_NOT_OWNED:
Toast.makeText(activity, "Product not owned error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_PRODUCT_CONSUMED:
Toast.makeText(activity, "Product consumed error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED:
Toast.makeText(activity, "Order account area not supported error!", Toast.LENGTH_SHORT).show();
return SOLVED;
case OrderStatusCode.ORDER_NOT_ACCEPT_AGREEMENT:
Toast.makeText(activity, "User does not agree the agreement", Toast.LENGTH_SHORT).show();
return SOLVED;
default:
// handle other error scenarios
Toast.makeText(activity, "Order unknown error!", Toast.LENGTH_SHORT).show();
return SOLVED;
}
} else {
Toast.makeText(activity, "external error", Toast.LENGTH_SHORT).show();
Log.e(TAG, e.getMessage());
return SOLVED;
}
}
In the video attached on the reject of the review, the toast with message "Order unknown error!" is shown.
But the same APK in Cloud Debugging works.
What is wrong with my code ?
来源:https://stackoverflow.com/questions/64872524/migration-from-google-play-store-to-huawei-store-any-changes-in-code