2.0.8 • Published 5 years ago
cordova-device-accounts-v2 v2.0.8
Cordova Device Accounts v2 Plugin
Cordova plugin to get the device accounts on Android.
Install
If you're using Ionic you can use the following commands:
ionic cordova plugin add cordova-device-accounts-v2 --save
npm install @ionic-native/device-accounts
Note: This is the official maintained repository for the "Device Account" plugin, view the Ionic documentation Here.
Otherwise use the following command:
cordova plugin add cordova-device-accounts-v2 --save
Required Permissions
Requires the following permissions:
- android.permission.GET_ACCOUNTS
- android.permission.GET_ACCOUNTS_PRIVILEGED
import { AndroidPermissions } from '@ionic-native/android-permissions';
constructor(private androidPermissions: AndroidPermissions) { }
...
return this.androidPermissions.requestPermissions(
[
this.androidPermissions.PERMISSION.GET_ACCOUNTS,
this.androidPermissions.PERMISSION.GET_ACCOUNTS_PRIVILEGED
])
.then(permission => console.log('Permissions Granted: ' + JSON.stringify(permission)))
.catch(error => console.error(error));
Methods
DeviceAccounts.get(onSuccess, onFail)
: get all accounts registered on deviceDeviceAccounts.getByType(type, onSuccess, onFail)
: get all accounts registered on device for requested typeDeviceAccounts.getEmails(onSuccess, onFail)
: get all emails registered on device (accounts with 'com.google' type)DeviceAccounts.getEmail(onSuccess, onFail)
: get the first email registered on device or undefinedDeviceAccounts.getPermissions(onSuccess, onFail)
: get all emails and request permissions from user.
Note: since Android 8.0.0+ device accounts are not visible to the application. Users must grant access to email accounts they wish to be visible to the application.
Example
import { DeviceAccounts } from '@ionic-native/device-accounts';
constructor(private deviceAccounts: DeviceAccounts) { }
...
this.deviceAccounts.get()
.then(accounts => console.log(accounts))
.catch(error => console.error(error));
A demo Ionic application can be viewed to see a working implementation of this plugin Here.
Compatibility
The following versions are compatible with this plugin:
- Cordova 3.3 +
- Android 4.4 +