@pavelety/cordova-plugin-google-play-services-check
v1.0.2
Published
Cordova/Ionic/Phonegap plugin for checking that the Google Play Services are installed, updated and enabled
Downloads
17
Maintainers
Readme
#Cordova Plugin Google Play Services Check Cordova/Ionic/Phonegap plugin for checking that the Google Play Services are installed, updated and enabled on Android device.
#Why Users' Google Play Services should be updated if you want to have more accurate and fast GPS. There is a native way to check and update it. No need to ask user to do it manual, just install this plugin.
#Installation The plugin can be installed via Cordova-CLI and is publicly available on NPM.
Execute from the project root folder:
$ cordova plugin add @pavelety/cordova-plugin-google-play-services-check
Or with Ionic
$ ionic cordova plugin add @pavelety/cordova-plugin-google-play-services-check
#Usage The plugin creates the object GooglePlayServices, and it's accessible after deviceready has been fired.
document.addEventListener('deviceready', function () {
var success = function(installedAndUpdated) {
if (installedAndUpdated.status) {
console.log('Google Play Services is installed and updated');
} else {
console.log('Showing user native update window');
}
}
var failure = function(reason) {
console.error('error: ' + reason)
}
GooglePlayServices.check(success, failure);
})
Or for Ionic-v4:
import { Platform } from '@ionic/angular';
@Component({...})
export class MyPage {
constructor(public platform: Platform) {
platform.ready().then(() => {
var success = function(installedAndUpdated) {
if (installedAndUpdated.status) {
console.log('Google Play Services is installed and updated');
} else {
console.log('Showing user native update window');
}
}
var failure = function(reason) {
console.error('error: ' + reason)
}
GooglePlayServices.check(success, failure);
});
}
}
Or enhanced example for Ionic-v1:
var googlePlayCheckedAndInstalled=false;
function googlePlayCheck() {
if (window.cordova && !googlePlayCheckedAndInstalled) {
var success = function (installedAndUpdated) {
console.log('Google Play Services success: ', installedAndUpdated);
if (installedAndUpdated.status) {
console.log('Google Play Services is installed and updated');
googlePlayCheckedAndInstalled = true;
} else {
console.log('Trying to show user native update window');
}
}
var failure = function (reason) {
console.error('Google Play Services error: ' + reason)
}
GooglePlayServicesCheck.check(success, failure);
}
}
googlePlayCheck();
$ionicPlatform.on('resume', function () {
googlePlayCheck();
});