Cordova plugin to get the device accounts on Android.
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
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));
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.
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.
The following versions are compatible with this plugin:
- Cordova 3.3 +
- Android 4.4 +
This is an open-source project and takes the time and effort of several individuals to maintain. If you like this plugin and use it within your applications, a donation would be greatly appreciated.