Reputation: 556
I have an android app , that i need to deploy for both Google play and App gallery
and it contains Ads and IAP , the problem is that
1- What is the correct way to handle the ads/purchase ?
if hmsAvailable() {
// use Huawei ads/iap
} else {
// use Google ads/iap
}
2- I need the same code base ,so Would it cause a problem to have both GMS and HMS inside Gradle.build ?
3- It seems that Huawei is about to prevent GMS installation on it's devices , so if a user has paid the premium IAP with a google account , would this means he can't restore it when GMS is blocked on Huawei ?
Upvotes: 3
Views: 1539
Reputation: 2025
You can define product flavors or check for GMS/HMS availability inside the code itself. GMS+HMS Product Flavors https://stackoverflow.com/a/61839463/14880637
gms { dimension "services" buildConfigField "String", "SERVICE_USED", '"g"'
}
hms {
dimension "services"
buildConfigField "String", "SERVICE_USED", '"h"'
}
GMS/HMS Availability Check https://stackoverflow.com/a/60587678/14880637
public static boolean isHmsAvailable(Context context) {
boolean isAvailable = false;
if (null != context) {
int result = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context);
isAvailable = (com.huawei.hms.api.ConnectionResult.SUCCESS == result);
}
Log.i(TAG, "isHmsAvailable: " + isAvailable);
return isAvailable;
}
public static boolean isGmsAvailable(Context context) {
boolean isAvailable = false;
if (null != context) {
int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
isAvailable = (com.google.android.gms.common.ConnectionResult.SUCCESS == result);
}
Log.i(TAG, "isGmsAvailable: " + isAvailable);
return isAvailable;
}
There is no issue with having both GMS and HMS in the gradle. ChoiceSDk is a good example which in use by published apps. https://www.hihonor.com/global/club/topicdetail/choice-sdk-gms-to-hms-apps-for-huawei-appgallery/topicId-69134/ You can see that ChoiceSDk requires both GMS and HMS configuration in the gradle. https://github.com/bluesource/ChoiceSDK
Huawei is not blocking GMS on their devices. Google has blocked GMS access to Huawei phones released after May 2019. https://www.pocket-lint.com/phones/news/huawei/148102-what-does-huawei-s-google-ban-mean-for-your-huawei-or-honor-phone. Because GMS is not available on Huawei phones released after May 2019, it will not be possible to access Google IAP from those devices. It's recommended that you store purchase history on your own server to ensure that users will still be able to access their premium purchase.
Upvotes: 1
Reputation: 34027
1- What is the correct way to handle the ads/purchase ?
You can make a judgment, but it is recommended that Google Play and App Gallery integrate their own Ads and IAP SDKs, and include Huawei and Google libraries.
2- I need the same code base ,so Would it cause a problem to have both GMS and HMS inside Gradle.build ?
On Google Play, only apps integrated with the Google IAP can be released. If the apps integrated with the HMS, the apps cannot be released.
There are no restrictions on Huawei App Gallery.
3- It seems that Huawei is about to prevent GMS installation on it's devices , so if a user has paid the premium IAP with a google account , would this means he can't restore it when GMS is blocked on Huawei ?
It is not that Huawei prevents the installation of the GMS, but that the GMS cannot be installed on Huawei devices.
Upvotes: 1
Reputation: 4585
I don't hear anything about blocking GMS by Huawei, but hear about blocking apps on google play if they have Huawei SDKs.
So, you should choose this way:
Create different flavors for different stores and include huawei/google libraries only for huawei/google flavor.
And yes, to restore iaps on different devices with different stores you have to store purchases info on your own server, not rely on response from store.
Upvotes: 2