Account Management
PUBLISHED
An account is a collection of information representing the user of a specific provider. You can manage accounts and their details in your application.
The main features of the Tizen.Account.AccountManager namespace include:
- Creating and managing accounts
You can create an account, set its properties, and insert it to the database.
You can also manage the account secrecy level and remove accounts.
- Retrieving account information
You can retrieve information for each existing account and implement an event handler.
You can also get accounts based on a specific account provider package name, or account providers based on a specific capability.
- Receiving account change notifications
- Modifying account properties
You can query the account details with database queries, retrieve the account type, and update the account information. For a list of modifiable account properties, see Account and Account Provider Properties.
To register an account provider, define the account provider information in the Account
tab of the manifest editor, and implement the account application control.
If the application has defined the account provider information and implements the appcontrol for the account provider, the account provider is automatically registered when the application is installed.
Account Application Control
The account application control, which allows the user to add and configure accounts, must be implemented in all applications that define an account provider. You are not required to define the application control information in the Application Control tab of the manifest editor to add the application on the Account screen.
This application control supports the http://tizen.org/appcontrol/operation/account/add
and http://tizen.org/appcontrol/operation/account/configure
operations.
ACCOUNT OPERATION SIGNIN Operation
The http://tizen.org/appcontrol/operation/account/add
operation enables the user to add a new account for a specific account provider.
With the operation, the login page for the specific account provider can be displayed. In Settings > Accounts, if the account provider is clicked for adding a new account, this operation is launched.
Table: ACCOUNT OPERATION SIGNIN operation
Operation | Description |
---|---|
http://tizen.org/appcontrol/operation/account/add |
Account ID of the added account. |
ACCOUNT OPERATION VIEW Operation
The http://tizen.org/appcontrol/operation/account/configure
operation enables the user to set account information, such as synchronization settings. The delete button must be included for removing accounts.
In Settings > Accounts, if the specific account is clicked for setting the account information, this operation is launched.
Table: ACCOUNT OPERATION VIEW operation
Operation | Description |
---|---|
http://tizen.org/appcontrol/operation/account/configure |
Account ID for setting account information. |
Prerequisites
To enable your application to use the account management functionality:
-
To use the Tizen.Account.AccountManager [1] namespace, the application has to request permission by adding the following privileges to the
tizen-manifest.xml
file:<privileges> <privilege>http://tizen.org/privilege/account.read</privilege> <privilege>http://tizen.org/privilege/account.write</privilege> </privileges>
-
To use the methods and properties of the Tizen.Account.AccountManager namespace, include it in your application:
using Tizen.Account.AccountManager;
Creating and Managing an Account
To create an account, set its properties, and add it to the account database:
- Create an account using the
CreateAccount()
method of the Tizen.Account.AccountManager.Account [2] class:Account account = Account.CreateAccount();
- When the account is created, you can set account properties, such as name, display name, domain name, and email ID:
string userName = "Marcus"; string displayName = "Marcus_display"; string domainName = "Marcus_domain"; string emailId = "marcus@example.com"; string iconPath = "image_path"; account.UserName = userName; account.DisplayName = displayName; account.DomainName = domainName; account.EmailId = emailId account.IconPath = iconPath;
- When the account properties are set, use the
AddAccount()
method of the Tizen.Account.AccountManager.AccountService [3] class to insert the account into the account database:
int account_id = AccountService.AddAccount(account);
The method returns the account ID (
account_id
) of the newly inserted account.
Getting Account Information
To get account information, such as user name, display name, domain name, and email ID:
- Use the
GetAccountsCount()
method of the Tizen.Account.AccountManager.AccountService [3] class to get the total number of records in the account database.To get individual records, use the
GetAccountsAsync()
method, which iterates through all the records and invokes an event handler for each account.int total_count = AccountService.GetAccountsCount(); IEnumerable<Account> accounts = AccountService.GetAccountsAsync();
- To get more details, use the
AccountId
,UserName
,DisplayName
, andIconPath
properties of the Tizen.Account.AccountManager.Account [2] class instance returned in the event handler:
Account account = Account.CreateAccount(); /// Get the account ID var id = account.AccountId; Console.WriteLine("Account ID: {0}", id); /// Get the user name string userName = account.UserName; Console.WriteLine("User Name: {0}", userName); /// Get the display name string display = account.DisplayName; Console.WriteLine("Display Name: {0}", display); /// Get the icon path string iconPath = account.IconPath; Console.WriteLine("Icon Path: {0}", iconPath);
Retrieving Accounts by Package Name
To retrieve accounts by a specific account provider, use the GetAccountsByPackageName()
method of the Tizen.Account.AccountManager.AccountService [3] class with the package name of the account provider:
IEnumerable<Account> accounts = null; string packageName = "packageName"; accounts = AccountService.GetAccountsByPackageName(packageName);
Retrieving Account Providers by Capability
To retrieve account providers by a specific capability, use the GetAccountProvidersByFeature()
method of the Tizen.Account.AccountManager.AccountService [3] class:
string capability = "http://tizen.org/account/capability/contact"; IEnumerable<AccountProvider> providers = AccountService.GetAccountProvidersByFeature(capability);
Removing an Account
Accounts to be removed can be identified by the account ID, user name, package name.
To remove an account, use the DeleteAccount()
method of the Tizen.Account.AccountManager.AccountService [3] class:
- Remove an account using an account ID:
Account account = Account.CreateAccount(); var id = account.AccountId; AccountService.DeleteAccount(account);
- Remove an account using a user name:
string userName = "user_name"; string packageName = "packageName"; AccountService.DeleteAccount(userName, packageName);
- Remove an account using a package name:
string packageName = "packageName"; AccountService.DeleteAccount(packageName);
Performing Database Queries
To perform database queries:
- Prepare sample content.
To perform queries, you need existing content in the database. To access an existing account, obtain it from the database. This can be done using a few different methods, depending on the user requirements.
To create new content and add it to the database:
- The
Create_Account()
method takes a new Tizen.Account.AccountManager.Account [2] instance and gives it some account details (name, display name, domain, email):void Create_Account(Account account, string userName, string displayName, string domainName, string emailId) { account.UserName = userName; account.DisplayName = displayName; account.domainName = domainName; account.EmailId = emailId; }
3 capabilities are added to the account to demonstrate some of the query functions. The capabilities as well as user custom types can be predefined.
After the account is created, it is added to the database.
Account account = Account.CreateAccount(); Create_Account(account, "Person", "DisplayPerson", "Person Domain", "someone1@somewho.com"); account.SetCapability("Custom", CapabilityState.Enabled); account.SetCapability("Next", CapabilityState.Enabled); account.SetCapability("Another", CapabilityState.Disabled); AccountService.AddAccount(account);
-
Add 2 more accounts to the database:
Create_Account(account, "Human", "Humanity", "Everyone", "someone3@somewho.com"); AccountService.AddAccount(account); Create_Account(account, "LastOne", "LastDisplay", "Last Domain", "someone4@somewho.com"); AccountService.AddAccount(account);
- The
- Get the accounts:
Get all accounts to verify the database insertion:
IEnumerable<Account> accounts = AccountService.GetAccountsAsync();
- Query the account by various attributes:
- Query by the ID:
IEnumerable<Account> accounts = null; List<int> values = new List<int>(); foreach (int i in values) { accounts = AccountService.GetAccountById(i); }
- Query by user name.
Querying data by user name requires a valid user name.
IEnumerable<Account> accounts = null; string userName = "Human"; accounts = AccountService.GetAccountsByUserName(userName);
- Query by package name.
By default, the accounts created in the application context have a package name set to the application name. Change it using the
PackageName
property of the Tizen.Account.AccountManager.Account [2] instance. To list accounts by package name, the user can provide a name by themselves or obtain it through thePackageName
property.IEnumerable<Account> accounts = null; Account account = Account.CreateAccount(); string packageName = account.PackageName; accounts = AccountService.GetAccountsByPackageName(packageName);
- Query by capability.
The
GetAccountsByCapabilityType()
method of the Tizen.Account.AccountManager.AccountService [3] class allows the user to find all accounts with a specified capability type.IEnumerable<Account> accounts = null; accounts = AccountService.GetAccountsByCapabilityType("Custom");
- Query capability by account ID.
The
GetCapabilitiesById()
method is different from the previous methods. It returns all capabilities from an account with a specified ID.Dictionary<string, CapabilityState> newcapabilities = AccountService.GetCapabilitiesById(account.AccountId);
- Query by the ID:
- Destroy all account instances when they are no longer needed:
account.Dispose();
Managing Account Secrecy
To manage account secrecy:
- The secrecy state of an account is set and fetched using the
SecrecyState
property of the Tizen.Account.AccountManager.Account [2] class, which uses values from the Tizen.Account.AccountManager.AccountSecrecyState [4] enumeration:int account1_id = 0, account2_id = 0, account3_id = 0; Account account = Account.CreateAccount(); /// Account 1 Create_Account(account, "Security 1", "Invalid", "NOBODY", "anony@mous.not"); account.SecrecyState = AccountSecrecyState.InvalidState; id = AccountService.AddAccount(account); /// Account 2 Create_Account(account, "Security 2", "Invisible", " NOBODY", "anony1@mous.not"); account.SecrecyState = AccountSecrecyState.Invisible; id = AccountService.AddAccount(account); /// Account 3 Create_Account(account, "Secret 3", "Visible", " NOBODY", "anony2@mous.not"); account.SecrecyState = AccountSecrecyState.Visible; id = AccountService.AddAccount(account); List_Accounts(NULL);
Secrecy is only linked with the visibility on the account settings screen. The account is still visible and can be accessed using a query or a
foreach
method./// List_Account() console output My ID: 12 My Name: Security 1 My Disp.: Invalid ------------------- My ID: 13 My Name: Security 2 My Disp.: Invisible ------------------- My ID: 14 My Name: Secret 3 My Disp.: Visible
Updating Accounts
To update and track account data:
- Create the account event handler.
If an event handler is registered and any action takes place on any account, the event handler provides in its parameters the event type as a string and the ID of the account associated with the actual change.
handler = (object sender, AccountSubscriberEventArgs args) => { Console.WriteLine("Callback Event Type: {0}, Account ID: {1}", args.EventType, args.accountId); };
Register the event handler for the
AccountUpdated
event of the Tizen.Account.AccountManager.AccountService [3] class:AccountService.AccountUpdated += handler;
- Create an account:
Account account = Account.CreateAccount(); Create_Account(account, "Updater", "Updated?", "ToUpdate", "not.up@to.date"); AccountService.AddAccount(account);
- Update the account:
- Get the account from the database based on its ID.
- Make the necessary changes.
- Update the account using the valid ID.
Account account = AccountService.GetAccountById(id); account.DisplayName = "Updated!"; AccountService.UpdateAccount(account);
- Show the account to verify the updates:
Account account = AccountService.GetAccountById(accountId); Show_Account(account);
- When it is no longer needed, deregister the event handler:
AccountService.AccountUpdated -= handler;
Retrieving Account Types
To retrieve account types:
- Get the type information.
If the account type with a specified ID exists, you can get it from the database with the
GetAccountProviderByAppId()
method of the Tizen.Account.AccountManager.AccountService [3] class.It is possible to set, for example:
- ID
- Labels
- Features
- Multiple account support (this is only a flag)
To get the account types by the application ID, use the
GetAccountProviderByAppId()
method:string appId = "com.tizen.example"; /// App ID for retrieving account types AccountProvider provider = AccountService.GetAccountProviderByAppId(appId); if (provider.IsAppSupported(appId)) { multipleAccountSupport = provider.MultipleAccountSupport; iconPath = provider.IconPath; features = AccountProvider.GetFeaturesByAppId(appId); }
- List the account types or all the labels from a specified type:
IEnumerable<AccountProvider> accountProviders = AccountService.GetAccountProviders(); Dictionary<string, string> labels = AccountProvider.GetLabelsByAppId(appId);
Account and Account Provider Properties
The following table lists the account properties that can be modified.
Table: Account properties
Account property | Data type | Mandatory | Description |
---|---|---|---|
User name | String |
Yes | Identity of an account.
If the display name and email ID are not set for an account, the user name is shown for the account on the Accounts screen in the Setting application. |
Display name | String |
No | Display name of an account.
Display name is shown for the account on the Accounts screen in the Setting application. |
Email ID | String |
No | Email ID of an account.
If the display name is not set for an account, the email ID is shown for the account on the Accounts screen in the Setting application. |
Package name | String |
No | One of an account package IDs, like the app ID.
If the package name is not set for an account, the app ID is used as a package name. |
Icon path | String |
No | Icon path of an account.
The icon is shown through the registered icon path as an account icon on the Accounts screen in the Setting application. |
Domain name | String |
No | Domain name of an account. |
Access token | String |
No | Access token of an account. |
Auth type | Integer |
No | Authentication type, such as oauth or xauth. |
Capability | Key-value string -integer pairs |
No | Capability of an account. |
Secret | Integer |
No | The secret value is used to decide whether the account is shown on the Accounts screen in the Setting application. |
Sync support | Integer |
No | Current synchronization status. |
Source | String |
No | Source of an account. |
User text | String |
No | String array, which you can use freely. |
User int | Integer |
No | Integer array, which you can use freely. |
Custom | Key-value string pairs |
No | Key-value pairs, which you can use freely. |
Safe account handle | SafeAccountHandle |
No | Read-only account handle of an account. |
The following table lists the properties that can be defined for each account provider.
Table: Account provider properties
Account property | Data type | Mandatory | Description |
---|---|---|---|
Multiple accounts support | bool |
Yes | Indicates whether multiple accounts are supported. |
Icon | String |
Yes | File path of the account provider icon.
The icon size is:
Since the icon is used in Settings > Accounts, place the icon in a shared directory. |
Small icon | String |
Yes | File path of the account provider icon.
The icon size is:
Since the small icon is used in other applications, place the icon in a shared directory. |
Display name | String |
Yes | Display name of the account provider. |
Capabilities | String |
No | Capability of the account provider.
Capability can be a liaison between an account application and another application. If an account application registers a capability in the manifest file, other applications know that the account application has the capability. And if an account application gives an account a capability, other applications know that the account has the capability. Several service-specific capabilities are defined for the Tizen.Account.AccountManager.AccountService [3] class:
|