capacitor-plugin-gmshms-checker

Plugin to check gms or hms availability

Usage no npm install needed!

<script type="module">
  import capacitorPluginGmshmsChecker from 'https://cdn.skypack.dev/capacitor-plugin-gmshms-checker';
</script>

README

capacitor-plugin-hmsgms-checker


capacitor-plugin-hmsgms-checker

Capacitor plugin for checking HMS or GMS availability..

Platforms Support

Only Android Platform is supported.

Installation

Using npm:

For Capacitor v2.x

npm install capacitor-plugin-hmsgms-checker@0.1.1

For Capacitor v3.x

npm install capacitor-plugin-hmsgms-checker@latest

Sync native files:

npx cap sync

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.x

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);
    }
}

Configuration

In your android/app/build.gradle add next line in your repositories entry

repositories {
    ...
    maven { url 'http://developer.huawei.com/repo/' }
}

NOTE: If your gradle version is ^7.x, add allowInsecureProtocol flag, your build gradle should look like:

repositories {
    ...
    maven { 
      url 'http://developer.huawei.com/repo/'
      allowInsecureProtocol = true
    }
}

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.x

// 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);
});

...

Android/Google

No more steps are needed. This plugin implements play-services-base version 17.6.0.

You may download the google-services.json file and copy it to android/app/ directory of your capacitor project.

Android/Huawei

No more steps are needed. This plugin implements hms:push version 6.1.0.300. You may download the agconnect-services.json file and copy it to android/app/ directory of your capacitor project.

Your Android Gradle plugin must be 3.5.4 or later

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 run npm install)
  • npx cap open android
  • add google-services.json or/and agconnect-services.json to your android/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.