Skip to content

mubasshir/cordova-android-accountmanager

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-android-accountmanager

Introduction

cordova-android-accountmanager is an Android AccountManager plugin for cordova-android.

It currently only supports explicit account handling (programatically adding/removing/settin/getting account details to the AccountManager).

Basic Usage (Explicit account handling)

var am = window.plugins.accountmanager;

// Add account explicitly
am.addAccountExplicitly('MyAccountType', 'bob', 'passwordbob', null, function(error, bob)
{
	// bob.name = 'bob'
	// bob.type = 'MyAccountType'

	// List all accounts of MyAccountType
	am.getAccountsByType('MyAccountType', function(error, accounts)
	{
		accounts.forEach(function(account)
		{
			console.log('Account: ' + JSON.stringify(account));
		});
	});

	// Get password
	am.getPassword(bob, function(error, password)
	{
		console.log("Bob's password: " + password);
	});
	
	am.setAuthToken(bob, 'authtoken', 'secret token');
	am.getAuthToken(bob, 'authtoken', true, function(error, token) {
		console.log("Bob's token: " + token);
	});

	// Get/Set user data
	am.setUserData(bob, 'age', 30);
	am.getUserData(bob, 'age', function(error, age)
	{
		console.log('Bob is ' + age + 'years old');
	});

	// Remove account
	am.removeAccount(bob);
});

Basic Usage (Authenticator based handling)

Not yet supported.

Project Setup

Installation - Cordova Command Line

cordova plugin add https://github.com/mubasshir/cordova-android-accountmanager.git

Installation - Manual ( Step 1 )

  1. Copy (or link) all the .java files into your project src (under the appropriate com.polychrom.cordova package).
  2. Copy accountmanager.js into your cordova app's www directory
  3. Add <script charset="utf-8" src="accountmanager.js"></script> to your cordova app's HTML.
  4. Copy (or link) authenticator.xml to your project's res/xml/ folder.

Installation - Manual ( Step 2 ) - Edit Android Manifest for Authenticator Service

To register the AuthenticatorService with your application, the following will need to be added to your manifest's application element:

<!-- The authenticator service -->
<service android:name="com.polychrom.cordova.AuthenticatorService" android:exported="false">
	<intent-filter>
		<action android:name="android.accounts.AccountAuthenticator" />
	</intent-filter>
	<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
</service>

Installation - Manual ( Step 3 ) - Add Permissions

Depending on the level of usage, the following permissions may be required by the plugin for correct usage:

Configuration options

This plugin can be configured via Android string resources (res/values/strings.xml) as follows:

  • [required] aam_account_type: Specifies the plugin's authenticator account type (this value must match the first parameter passed into accountmanager.addAccountExplicitly) MyCustomAccountName

See the AccountManager documentation for specific requirements for each function.

About

Cordova Android AccountManager plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 56.4%
  • JavaScript 27.0%
  • CSS 13.0%
  • HTML 3.6%