【发布时间】:2020-11-17 09:27:59
【问题描述】:
我在 Google Play 商店中有一个应用程序。 我也打算在华为商店发布。
除了使用华为SDK重新构建应用程序和基本的指导步骤(添加到项目agconnect-services.json等)之外,还有什么需要在代码级别进行更改的吗?
所有 API 都在工作吗?特别是那些与应用内购买相关的?
谢谢
【问题讨论】:
标签: huawei-mobile-services huawei-developers huawei-iap
我在 Google Play 商店中有一个应用程序。 我也打算在华为商店发布。
除了使用华为SDK重新构建应用程序和基本的指导步骤(添加到项目agconnect-services.json等)之外,还有什么需要在代码级别进行更改的吗?
所有 API 都在工作吗?特别是那些与应用内购买相关的?
谢谢
【问题讨论】:
标签: huawei-mobile-services huawei-developers huawei-iap
首先,请查看您使用的是什么 GMS Kit,我可以为您提供相应的 HMS Kit。也可以参考this answer。
在代码级别,如果您愿意:
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;
}
代码调用逻辑:
If ( isGMS() ) {
//GMS code
}else if ( isHMS() ){
//HMS code
}
HMS 提供类似于 GMS 的接口。这里是IAP documentation 和Github。
也可以使用HMS ToolKit实现G2H/G+H。
更新:
可以使用以下代码获取productId:
PurchaseResultInfo buyResultInfo = Iap.getIapClient(this).parsePurchaseResultInfoFromIntent(data);
getInAppPurchaseData() 方法是通过 PurchaseResultInfo 声明的 buyResultInfo 对象调用的。 getInAppPurchaseData方法调用成功后即可获取InAppPurchaseData。
当前交易的产品 ID 存储在 InAppPurchaseData 中。 见:here。
【讨论】:
@shirley,是的,我实际上也找到了。
以下代码在所有设备的云调试中都能正常运行,但不适用于审核。 因此该应用程序被拒绝。
活动类内部:
private IapClient mIAPClient;
关于活动创建:
mIAPClient = Iap.getIapClient(this);
当用户点击触发应用内购买的按钮时:
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;
}
}
}
});
}
上面捕获了一个异常 onFail(Exception e)。 在尝试从 ExceptionHandle 获取 errorCode 时,我什么也没得到。
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;
}
}
在拒绝评论的视频中,带有“订单未知错误!”消息的祝酒词显示出来了。
但是云端调试中的同一个 APK 可以工作。
我的代码有什么问题?
【讨论】: