capacitor-plugin-gmshms-checker
v6.0.0
Published
Capacitor plugin to check GMS and HMS availability
Downloads
284
Maintainers
Readme
capacitor-plugin-hmsgms-checker
Platforms Support
Only Android Platform is supported.
Installation
Using npm:
npm install capacitor-plugin-hmsgms-checker@latest
Sync native files:
npx cap sync
Version Compatibility
On capacitor v6 migration, no breaking changes are reported, but major number version jump to 6 to better understanding of this plugin-capacitor compatibility.
| Capacitor Version | Plugin Version | Install Command |
| --- | --- | --- |
| Capacitor V2 | 1.0.0 | npm i capacitor-plugin-gmshms-checker@1
|
| Capacitor V3 | 2.0.0 | npm i [email protected]
|
| Capacitor V4 | 2.1.0 | npm i [email protected]
|
| Capacitor V5 | 3.0.0 | npm i capacitor-plugin-gmshms-checker@3
|
| Capacitor V6 | 6.0.0 | npm i capacitor-plugin-gmshms-checker@latest
|
||||
On Android, register the plugin in your main activity:
Capacitor v2.x
import com.angelcamacho.plugin.ServiceChecker;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
// Additional plugins you've installed go here
add(ServiceChecker.class);
}
}
);
}
}
Capacitor v3+
import com.angelcamacho.plugin.ServiceChecker;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Additional plugins you've installed go here
registerPlugin(ServiceChecker.class);
}
}
Capacitor v4+
import com.angelcamacho.plugin.ServiceChecker;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
// Additional plugins you've installed go here, diffent order compared with capV3
registerPlugin(ServiceChecker.class);
super.onCreate(savedInstanceState);
}
}
Configuration
In your android/build.gradle
file add next lines in your buildscript > repositories
and buildscript > dependencies
entries.
buildscript{
repositories {
...
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.9.0.300'
}
Then, in your allprojects > repositories
entry add next line
allprojects {
repositories {
...
maven { url 'https://developer.huawei.com/repo/' }
}
}
In your android/app/build.gradle
file add next line in your repositories entry
repositories {
...
maven { url 'http://developer.huawei.com/repo/' }
}
WARN: If your gradle version is ^7.x, add allowInsecureProtocol flag, so your build gradle should look like:
repositories {
...
maven {
url 'http://developer.huawei.com/repo/'
allowInsecureProtocol = true
}
}
Your Android Gradle plugin must be 4.2.1 or later
Usage
Capacitor v2.x
// Must import the package once to make sure the web support initializes
...
import 'capacitor-plugin-gmshms-checker';
import { Plugins } from "@capacitor/core";
const { ServiceChecker } = Plugins;
...
/**
* Platform: Android
* Gets true if GMS are available on the device
* @param none
* @returns object {value: boolean} - boolean indicates if GMS are available
*/
ServiceChecker.isGMSAvailable().then(({ value }) => {
// use value to do something
console.log(value);
});
/**
* Platform: Android
* Gets true if HMS are available on the device
* @param none
* @returns object {value: boolean} - boolean indicates if HMS are available
*/
ServiceChecker.isHMSAvailable().then(({ value }) => {
// use value to do something
console.log(value);
});
...
Capacitor v3+
// Must import the package once to make sure the web support initializes
...
import { ServiceChecker } from 'capacitor-plugin-gmshms-checker';
import 'capacitor-plugin-gmshms-checker';
...
/**
* Platform: Android
* Gets true if GMS are available on the device
* @param none
* @returns object {value: boolean} - boolean indicates if GMS are available
*/
ServiceChecker.isGMSAvailable().then(({ value }) => {
// use value to do something
console.log(value);
});
/**
* Platform: Android
* Gets true if HMS are available on the device
* @param none
* @returns object {value: boolean} - boolean indicates if HMS are available
*/
ServiceChecker.isHMSAvailable().then(({ value }) => {
// use value to do something
console.log(value);
});
...
For Google
No more steps are needed. This plugin implements play-services-base
version 18.1.0
.
You may download the google-services.json
file and copy it to android/app/
directory of your capacitor project.
For Huawei
No more steps are needed. This plugin implements hms:base
version 6.5.0.300
.
You may download the agconnect-services.json
file and copy it to android/app/
directory of your capacitor project.
Android setup
ionic start my-cap-app --capacitor
cd my-cap-app
npm install --save capacitor-plugin-hmsgms-checker
mkdir www && touch www/index.html
npx cap add android
npx cap sync android
(every time you runnpm install
)npx cap open android
- add
google-services.json
or/andagconnect-services.json
to yourandroid/app
folder
Now you should be set to go. Try to run your client using ionic cap run android --livereload --address=0.0.0.0
.
Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.