Using Huawei Availability Plugin in Flutter Apps

Sinan Aktepe
2 min readJul 5, 2021

Hello everyone,

In this article we’re going to learn how to detect HMS Core apk availability on android devices. Let’s dive into it!

Integrating Availability Plugin

  • Open the android/build.gradle file and set minSdkVersion to 19.

It’s all set up. We’re ready to use the plugin.

Using Huawei Availability Plugin

Our goal here is detecting whether the HMS Core Apk is installed on device or not. If there is not, we want users to install the Apk. Let’s see how we can achieve this.

Detecting HMS Core Apk

  • The plugin has the HmsApiAvailability class which provides all APIs we need. So let’s create an instance of this class.
  • In case the device doesn’t have the HMS Core Apk installed, we want to be notified about installation result events. To achieve this, we can specify a result listener to the HmsApiAvailability instance we’ve created. You can refer here for details on AvailabilityEvent.
  • The plugin comes with isHMSAvailable method to check HMS Core Apk existence. This method returns an Integer result code. 0 determines that device has the apk installed. Refer here for all result codes.

If the result code is different than 0, we want to request for HMS Core Apk installation. For that, we should install Huawei AppGallery to our device so the plugin can navigate to the store.

  • As the last step, request for installation with getErrorDialog method. You can use some other methods for installation. Please refer here for all methods.

That’s it! We successfully integrated the Huawei Availability Plugin to our Flutter application. You can find the demo application here.

Conclusion

We learned how to detect & request HMS Core Apk installation on an android device. HMS Kits and plugins have you covered with many more other features. Don’t forget to check out following links to learn more.

References & Further Reading

--

--