Check the availability of Google Play services on the current device

Overview

Flutter Google Api Availability Plugin

pub package Build status codecov

A Flutter plugin to check the availability of Google Play services on the current device.

Features

  • Check the availability of Google Play services (on Android only).

Usage

To use this plugin, add google_api_availability as a dependency in your pubspec.yaml file. For example:

dependencies:
  google_api_availability: ^3.0.1

NOTE: There's a known issue with integrating plugins that use Swift into a Flutter project created with the Objective-C template. See issue Flutter#16049 for help on integration.

API

GoogleApiAvailability

To check the availability of Google Play services on the current device, you can use the checkGooglePlayServicesAvailability method. This could be helpful to provide a more friendly experience to users in case an user-action is required to enable support for Google Play services (More information can be found here).

import `package:google_api_availability/google_api_availability.dart`;

GooglePlayServicesAvailability availability = await GoogleApiAvailability.instance.checkGooglePlayServicesAvailability();

If you want to show a dialog by the Android system with more information and show a possible fix to the user you can do:

import `package:google_api_availability/google_api_availability.dart`;

GooglePlayServicesAvailability availability = await GoogleApiAvailability.instance.checkGooglePlayServicesAvailability(true);

Note that on iOS this will always return notAvailableOnPlatform!

See also the example project for a complete implementation.

Issues

Please file any issues, bugs or feature request as an issue on our GitHub page.

Want to contribute

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our contribution guide and send us your pull request.

Author

This Google Api Availability plugin for Flutter is developed by Baseflow. You can contact us at [email protected]

Comments
  • Updated plugin and made small improvements and changes

    Updated plugin and made small improvements and changes

    :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

    • Updated pubspec.yaml to newer versions of SDK and flutter and adding flutter_lints as a dependency;
    • Updated analysis_options.yaml for using flutter_lints;
    • Updated code according to the set lint rule(s);
    • Updated compileSdkVersion and targetSdkVersion in the build.gradle
    • Fixed bug were starting the example app would close on running for the first time by adding internet permission in the AndroidManifest

    :arrow_heading_down: What is the current behavior?

    :new: What is the new behavior (if this is a feature change)?

    :boom: Does this PR introduce a breaking change?

    No

    :bug: Recommendations for testing

    :memo: Links to relevant issues/docs

    :thinking: Checklist before submitting

    • [x] All projects build
    • [x] Follows style guide lines (code style guide)
    • [x] Relevant documentation was updated
    • [x] Rebased onto current develop
    opened by JDDV 5
  • GoogleApiAvailability() doesn't have a default constructor

    GoogleApiAvailability() doesn't have a default constructor

    🐛 Bug Report

    I copy-past this line of code from your package Readme page:

    GooglePlayServicesAvailability availability = await GoogleApiAvailability().checkGooglePlayServicesAvailability();

    But I immediately get the error:

    The class 'GoogleApiAvailability' doesn't have a default constructor. Try using one of the named constructors defined in 'GoogleApiAvailability'.

    Version: 2.0.4

    Platform:

    • [ ] :robot: Android
    opened by kari538 5
  • Do not rely on the Activity object when this plugin is instantiated.

    Do not rely on the Activity object when this plugin is instantiated.

    :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

    Bug fix

    :arrow_heading_down: What is the current behavior?

    Plugin is incompatible with background isolates which may be held by a service on Android

    :new: What is the new behavior (if this is a feature change)?

    Plugin will depend on the generic Context class and cast to activity (if available) to show the google play services warning fragment.

    :boom: Does this PR introduce a breaking change?

    No

    :bug: Recommendations for testing

    Setup a background isolate holder Service

    :memo: Links to relevant issues/docs

    :thinking: Checklist before submitting

    • [ ] All projects build
    • [x] Follows style guide lines (code style guide)
    • [ ] Relevant documentation was updated
    • [x] Rebased onto current develop
    opened by ened 5
  • NPE when running in a background service

    NPE when running in a background service

    🔙 Regression

    The plugin shows a error when being started in a background service. This seems to be related to the V2 embedding.

    Old (and correct) behavior

    No crash on V1 embedding.

    Current behavior

    2020-03-31 22:30:26.265 15821-15821/com.mynextbase.connect E/MethodChannel#flutter.baseflow.com/google_api_availability/methods: Failed to handle method call
        java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
            at com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(Unknown Source:12)
            at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source:5)
            at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(com.google.android.gms:play-services-base@@17.1.0:96)
            at com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source:3)
            at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(com.google.android.gms:play-services-base@@17.1.0:95)
            at com.baseflow.googleapiavailability.GoogleApiAvailabilityPlugin.onMethodCall(GoogleApiAvailabilityPlugin.java:105)
            at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:226)
            at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
            at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:631)
            at android.os.MessageQueue.nativePollOnce(Native Method)
            at android.os.MessageQueue.next(MessageQueue.java:336)
            at android.os.Looper.loop(Looper.java:174)
            at android.app.ActivityThread.main(ActivityThread.java:7356)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
    

    Reproduction steps

    Run the plugin in a background service.

    Configuration

    Version: 2.0.3

    Platform:

    • [ ] :iphone: iOS
    • [x] :robot: Android

    The implementation of the V2 embedding seems a little complicated. The applicationContext should always be available to the GoogleApiAvailabilityPlugin class, and "activity" could be set depending on whether the activity has been connected or not.

    The check

          if (context instanceof Activity) {
            Activity activity = (Activity) context;
            if (showDialog != null && showDialog) {
              googleApiAvailability.showErrorDialogFragment(activity, connectionResult, REQUEST_GOOGLE_PLAY_SERVICES);
            }
          }
    

    could then be replaced by "if (activity != null)".

    opened by ened 4
  • Type inference failed. Expected type mismatch: inferred type is Boolean? but Boolean was expected

    Type inference failed. Expected type mismatch: inferred type is Boolean? but Boolean was expected

    🐛 Bug Report

    kotlin_version = '1.2.30'

    Launching lib/main.dev.dart on ONEPLUS A6000 in debug mode... Initializing gradle... Resolving dependencies... Gradle task 'assembleDevDebug'... Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: /Users/sandeeepcmsm/.pub-cache/hosted/pub.dartlang.org/flutter_webview_plugin-0.2.1+2/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /Users/sandeeepcmsm/.pub-cache/hosted/pub.dartlang.org/flutter_webview_plugin-0.2.1+2/android/src/main/java/com/flutter_webview_plugin/WebviewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. e: /Users/sandeeepcmsm/.pub-cache/hosted/pub.dartlang.org/google_api_availability-1.0.2/android/src/main/kotlin/com/baseflow/googleapiavailability/GoogleApiAvailabilityPlugin.kt: (29, 48): Type inference failed. Expected type mismatch: inferred type is Boolean? but Boolean was expected

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':google_api_availability:compileDebugKotlin'.

    Compilation error. See log for more details

    Reproduction steps

    Configuration

    Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel master, v0.9.7-pre.35, on Mac OS X 10.14 18A391, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK 28.0.3) [✓] iOS toolchain - develop for iOS devices (Xcode 10.0) [✓] Android Studio (version 3.2) [!] IntelliJ IDEA Community Edition (version 2018.1.5) ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. [✓] VS Code (version 1.27.2) [✓] Connected device (2 available)

    ! Doctor found issues in 1 category. Version: 1.x

    Platform:

    • [ ] :robot: Android
    opened by sandeepcmsm 4
  • Incorrect semver when updated to AndroidX

    Incorrect semver when updated to AndroidX

    🐛 Bug Report

    This library did not follow proper semver when it updated to AndroidX. Version 1.0.5 was updated to AndroidX and this is a breaking change yet the previous version was 1.0.4!

    This could be an even bigger problem if this library is used as a transitive dependency from another library (as it was in my case) as it is not obvious that this library is the issue.

    I was able to work around this issue by doing the following in my pubspec.yaml:

    dependency_overrides:
      google_api_availability: 1.0.4
    

    Expected behavior

    I should be able to put google_api_availability: ^1.0.0 in my pubspec.yaml and rely on that any versions within 1.0.x will not break me. This is proper semver and Dart's versioning relies heavily on libraries following semver. The proper version update for the AndroidX compatible release should have been 1.1.0. This would have ensured that only people who manully updated to ^1.1.0 would get the breaking change. To see an example of how to do this, look at the cloud_firestore changelog.

    Reproduction steps

    Put google_api_availability: ^1.0.0 in a project that has not been updated to AndroidX. You will get errors when it tries to multidex. Something like:

    Execution failed for task ':app:transformClassesWithMultidexlistForRelease'.
    > com.android.build.api.transform.TransformException: Error while generating the main dex list.
    

    Configuration

    A Flutter project that is not updated to AndroidX and uses multidex.

    Version: 1.0.5

    Platform:

    • [ ] :iphone: iOS
    • [x] :robot: Android
    opened by jonjon1123 3
  • Upgrade Kotlin version

    Upgrade Kotlin version

    🐛 Bug Report

    I can't upgrade the latest Gradle plugin version to (>3.2.0) because of this plugin. Which in turn leaves me unable to use the new app format (Android App Bundle). This is because this plugin expects kotlin plugin to be at version 1.2.71. For the new Gradle plugin the kotlin version must be at least 1.3.0.

    Expected behavior

    the app should compile

    Reproduction steps

    add this plugin (or for instance geolocator, which has this as a dependency) and allow Android Studio to upgrade to the latest Gradle.

    Configuration

    Android studio version 3.3 on windows, flutter updated to latest version

    Version: 1.0.4

    Platform:

    • [ ] :iphone: iOS
    • [X ] :robot: Android
    opened by yvanvds 3
  • fatal error: 'google_api_availability/google_api_availability-Swift.h' file not found

    fatal error: 'google_api_availability/google_api_availability-Swift.h' file not found

    🐛 Bug Report

    I'm facing this error trying to build my Flutter project for iOS with "flutter build ios" command:

    Building com.*******.mobile for device (ios-release)... Automatically signing iOS for device deployment using specified development team in Xcode project: ********* Running pod install... 2.0s Starting Xcode build...
    Xcode build done. 24.9s Failed to build iOS app Error output from Xcode build: ↳ ** BUILD FAILED **

    Xcode's output: ↳ /Users/dev/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/google_api_availability-1.0.2/ios/Classes/GoogleApiAvailabilityPlugin.m:2:9: fatal error: 'google_api_availability/google_api_availability-Swift.h' file not found #import <google_api_availability/google_api_availability-Swift.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. /Users/dev/Documents/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-2.0.1/ios/Classes/GeolocatorPlugin.m:2:9: fatal error: 'geolocator/geolocator-Swift.h' file not found #import <geolocator/geolocator-Swift.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. Encountered error while building for device.

    This is the output of flutter doctor:

    Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel beta, v0.7.3, on Mac OS X 10.13.2 17C88, locale en-BG) [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.io/setup/#android-setup for detailed instructions). If Android SDK has been installed to a custom location, set $ANDROID_HOME to that location. [✓] iOS toolchain - develop for iOS devices (Xcode 9.2) [✗] Android Studio (not installed) [!] IntelliJ IDEA Ultimate Edition (version 2017.2.5) ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality. [!] Connected devices ! No devices available

    This is how my pubspec.yaml file looks like:

    name: **** description: ***

    version: 1.0.0+1

    environment: sdk: ">=2.0.0-dev.68.0 <3.0.0"

    dependencies: flutter: sdk: flutter intl: 0.15.7 cupertino_icons: ^0.1.2 http: 0.11.3+17 shared_preferences: 0.4.2 google_api_availability: ^1.0.2 geolocator: ^2.0.1

    dev_dependencies: flutter_test: sdk: flutter

    flutter: uses-material-design: true

    The SWIFT_VERSION from Xcode is 4.0. Any help will be very much appreciated.

    Version: 1.0.2

    Platform:

    • [x] :iphone: iOS
    • [ ] :robot: Android
    opened by bbozhidarov 3
  • Support null safety

    Support null safety

    🚀 Feature Requests

    This is a request to add support for null safety to package:google_api_availability. We depend on your awesome package, so would be great to have null safety enabled.

    Contextualize the feature

    The Dart/Flutter team already encourages publishing the migrated packages: See this blog post.

    Describe the feature

    See the migration guide for details about enabling null safety.

    Platforms affected (mark all that apply)

    • [x] :iphone: iOS
    • [x] :robot: Android
    opened by IchordeDionysos 2
  • Fixes #17

    Fixes #17

    :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

    Bugfix

    :arrow_heading_down: What is the current behavior?

    See #17

    :boom: Does this PR introduce a breaking change?

    no

    :bug: Recommendations for testing

    Attempt to run the code in a background service

    :memo: Links to relevant issues/docs

    fixes #17

    :thinking: Checklist before submitting

    • [x] All projects build
    • [x] Follows style guide lines (code style guide)
    • [x] Relevant documentation was updated
    • [x] Rebased onto current develop

    Looks like this PR needs to be rebased (or develop does?).

    Please do not merge yet, will have a go at a basic e2e test.

    platform: android type: enhancement 
    opened by ened 2
  • Remove usage of jCenter

    Remove usage of jCenter

    🐛 Bug Report

    This library still uses jCenter. jCenter doesn't get any updates anymore and should therefor be switched to mavenCentral.

    See also https://developer.android.com/studio/build/jcenter-migration

    Expected behavior

    No dependencies on jCenter

    Platform:

    • [ ] :iphone: iOS
    • [x] :robot: Android
    opened by ueman 1
  • MissingPluginException

    MissingPluginException

    🐛 Bug Report

    I installed the package and imported it like this:

    import 'package:google_api_availability/google_api_availability.dart';
    

    Then in an async function I did this:

    final availability = await GoogleApiAvailability.instance.checkGooglePlayServicesAvailability(true);
    

    When I called function while running in an Android emulator I got this error:

    ERROR:flutter[/lib/ui/ui_dart_state.cc]()(209)] Unhandled Exception: MissingPluginException(No implementation found for method checkPlayServicesAvailability on channel flutter.baseflow.com[/google_api_availability/methods]()
    

    Expected behavior

    I expected no error and an indication of whether the Google Play services are available.

    Configuration

    Version: 3.0.1

    Platform:

    • [ ] :iphone: iOS
    • [X] :robot: Android
    opened by mvolkmann 6
  • Changed native code structure, added more functionality

    Changed native code structure, added more functionality

    :sparkles: What kind of change does this PR introduce? (Bug fix, feature, docs update...)

    Changed native code structure

    Added the following functionality:

    • makeGooglePlayServicesAvailable
    • getErrorString
    • isUserResolvable
    • showErrorNotification
    • showErrorDialogFragment

    :arrow_heading_down: What is the current behavior?

    :new: What is the new behavior (if this is a feature change)?

    Now the plugin is able to:

    • Tell the user if it's possible (and show UI or opens Google Play Store if necessary) to make Google Play Service available using makeGooglePlayServicesAvailable
    • Get a human-readable (error) code of the current status using getErrorString
    • Get a boolean whether the error can be resolved by the user (e.g. turning Google Play Services on) using isUserResolvable
    • Show a notification with error if there is an error with the connection status of Google Play Services using showErrorNotification (provided for background tasks that cannot or should not display dialogs).
    • Displays a DialogFragment if the connection result is not success with a clear text of the error using showErrorDialogFragment.

    :boom: Does this PR introduce a breaking change?

    No

    :bug: Recommendations for testing

    :memo: Links to relevant issues/docs

    https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability

    :thinking: Checklist before submitting

    • [x] All projects build
    • [x] Follows style guide lines (code style guide)
    • [x] Relevant documentation was updated
    • [x] Rebased onto current develop
    opened by JDDV 2
Owner
Baseflow
We provide software, skills and knowledge and with this we want to make a contribution to the world. We love to make innovation happen.
Baseflow
A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision.

Smart Notes A note-taking app powered by Google services such as Google Sign In, Google Drive, and Firebase ML Vision. This is an official entry to Fl

Cross Solutions 88 Oct 26, 2022
A lightweight flutter plugin to check if your app is up-to-date on Google Play Store or Apple App Store

App Version Checker this package is used to check if your app has a new version on playstore or apple app store. or you can even check what is the lat

Iheb Briki 6 Dec 14, 2022
[Flutter package] An easy and quick way to check if the local app is updated with the same version in their respective stores (Play Store / Apple Store ).

Retrieve version and url for local app update against store app Android and iOS Features Using as reference packages like in_app_update , version_chec

Kauê Murakami 11 Nov 9, 2022
SSH no ports provides ssh to a remote Linux device with out that device having any ports open

Ssh! No ports ssh no ports provides a way to ssh to a remote linux host/device without that device having any open ports (not even 22) on external int

The Atsign Foundation 224 Dec 21, 2022
The purpose of this project was to test Google Map Services in connection with Flutter on Android, iOS

A large variety of apps depend on map services. The purpose of this project was to test Google Map Services in connection with Flutter on Android, iOS and Web platforms. Here is what I got:

Derek Jones 15 Oct 17, 2022
Flutter Plugin for Requesting and Writing Reviews in Google Play and the App Store

Flutter Plugin for Requesting and Writing Reviews in Google Play and the App Store. Apps have to be published for the app to be found correctly.

Flutter Community 274 Jan 4, 2023
Let's create a selectable Flutter Navigation Drawer with routing that highlights the current item within the Flutter Sidebar Menu.

Flutter Tutorial - Sidebar Menu & Selectable Navigation Drawer Let's create a selectable Flutter Navigation Drawer with routing that highlights the cu

Johannes Milke 12 Dec 26, 2022
App that shows your current location weather and forecast

Weather APP Platform: Flutter. A project that shows you the weather and the forecast for the next five days in your current location. Uses openweather

Alberto Penas Amor 9 Aug 13, 2022
A powerful official extension library of Tab/TabBar/TabView, which support to scroll ancestor or child Tabs when current is overscroll, and set scroll direction and cache extent.

extended_tabs Language: English | 中文简体 A powerful official extension library of Tab/TabBar/TabView, which support to scroll ancestor or child Tabs whe

FlutterCandies 185 Dec 13, 2022
Declaratively switch child widgets based on the current `Router` location.

Features Declaratively switch child widgets based on the current Router location. class SideBar extends StatelessWidget { Widget build(_){ re

gskinner team 7 Dec 12, 2022
null 1 Jan 20, 2022
SoundVolumeView that displays general information and the current volume level for all active sound components in your system, and allows you to instantly mute and unmute them

SoundVolumeView that displays general information and the current volume level for all active sound components in your system, and allows you to instantly mute and unmute them

Domingo 4 Mar 4, 2022
this app will help you to check BMI.

bmicalfinal A new Flutter application. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

null 4 Dec 15, 2021
Flutter guide + SDK. Check Community repository for common information.

freeRASP for Flutter freeRASP for Flutter is a part of security SDK for the app shielding and security monitoring. Learn more about provided features

Talsec 63 Dec 26, 2022
CoVAC is an all-in-one Covid info toolkit app, providing users the facility to check for available slots along with receiving the latest updates related to the pandemic and the virus.

CoVAC - Covid 19 Vaccine Availability Checker Introduction ?? CoVAC is an android application developed to provide users the facility to check the ava

Aryan Kenchappagol 6 Dec 29, 2021
A package containing different kinds of services and utilities.

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Daniel 0 Nov 26, 2021
A beautiful, secure and simple authenticator app that supports multiple protocols and services. Free and open source. Written in Flutter and Dart.

OpenAuth A beautiful, secure and simple authenticator app that supports multiple protocols and services. Free and open source. Written in Flutter and

Isaiah Collins Abetong 31 Oct 5, 2022
Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

Flutter permission_handler plugin The Flutter permission_handler plugin is build following the federated plugin architecture. A detailed explanation o

Baseflow 1.7k Dec 31, 2022