Everyone likes it when you remember their name. One of the simplest, most effective things you can do to make your app more lovable is to remember who your user is—especially when the user upgrades to a new device or starts carrying a tablet as well as a
phone. But how do you know who your user is? And how do you recognize them on a new device?
For many applications, the answer is the AccountManager
APIs. With the user's permission, you can use Account Manager to fetch the account names that the user has stored on their device. http://blog.csdn.net/sergeycao
Integration with the user's accounts allows you to do a variety of things such as:
- Auto-fill forms with the user's email address.
- Retrieve an ID that is tied to a user, not the device.
Determine if AccountManager for You
Applications typically try to remember the user using one of three techniques:
- Ask the user to type in a username
- Retrieve a unique device ID to remember the device
- Retrieve a built-in account from
AccountManager
Option (a) is problematic. First, asking the user to type something before entering your app will automatically make your app less appealing. Second, there's no guarantee that the username chosen will be unique.
Option (b) is less onerous for the user, but it's
tricky to get right. More importantly, it only allows you to remember the user on one device. Imagine the frustration of someone who upgrades to a shiny new device, only to find that your app no longer remembers them.
Option (c) is the preferred technique. Account Manager allows you to get information about the accounts that are stored on the user's device. As we'll see in this lesson, using Account Manager lets you remember your user, no matter how many devices the user
may own, by adding just a couple of extra taps to your UI.
Decide What Type of Account to Use
Android devices can store multiple accounts from many different providers. When you query
AccountManager
for account names, you can choose to filter by account type. The account type is a string that uniquely identifies the entity that issued the account. For instance, Google accounts have type "com.google," while Twitter
uses "com.twitter.android.auth.login."
Request GET_ACCOUNT permission
In order to get a list of accounts on the device, your app needs the GET_ACCOUNTS
permission. Add a
<uses-permission>
tag in your manifest file to request this permission:
<manifest ... >
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
...
</manifest>
Query AccountManager for a List of Accounts
Once you decide what account type you're interested in, you need to query for accounts of that type. Get an instance of
AccountManager
by calling AccountManager.get()
. Then use that instance to call
getAccountsByType()
.
AccountManager am = AccountManager.get(this); // "this" references the current Context
Account[] accounts = am.getAccountsByType("com.google");
This returns an array of Account
objects. If there's more than one
Account
in the array, you should present a dialog asking the user to select one.
Use the Account Object to Personalize Your App
The Account
object contains an account name, which for Google accounts is an email address. You can use this information in several different ways, such as:
- As suggestions in forms, so the user doesn't need to input account information by hand.
- As a key into your own online database of usage and personalization information.
Decide Whether an Account Name is Enough
An account name is a good way to remember the user, but the Account
object by itself doesn't protect your data or give you access to anything besides the user's account name. If your app needs to allow the user to go online to
access private data, you'll need something stronger: authentication. The next lesson explains how to authenticate to existing online services. The lesson after that deals with writing a custom authenticator so that you can install your own account types.
分享到:
相关推荐
它处理登录、注销和长时间记住用户会话的常见任务。 Flask登录不绑定到任何特定的数据库系统或权限模型。唯一的要求是您的用户对象实现几个方法,并且您提供对扩展的回调,该扩展能够从用户ID加载用户。 Flask-Login...
ResRep Lossless CNN Pruning via Decoupling Remembering and Forgetting
Remembering user name and password Cover Art Thumbs Up / Thumbs Down / Tired of this song Notification popup with song info Launching pandora.com song info page and station page Reconnecting ...
记忆描述: Do you remember the past?You lived hard. Now, you need to take some rest by remembering your past.Run `/flag`... I'll not provide Dockerfile of this challenge.Author:`sqrtrev#9113`File ...
R2012b代码Value_Directed_Remembering-tDCS 该存储库包含由Linfeng Han(Tony)编写的实验和数据分析代码,用于经颅直流电刺激前外侧前额叶皮层对记忆编码的价值激励调制的影响。 直接主管:加州大学洛杉矶分校心理...
Are You Remembering to Ask Tough Questions? Link Counts, Hard Links, and Symbolic Links Increasing Your Privileges or Capabilities Background Processes and Credentials Access Control in NT NT ...
がいじんのべんきょう!-离线日语学习
名称/关键字:知识树。 给树吗? 知识的苹果? 思维导图卡片间隔重复键盘快捷方式:选择左:选择父节点右:至中间子级上/下:遍历相同级别的子级Cmd单击:选择多个创建节点(不编辑时)选项卡:末尾的新子代Shift-...
You will need to configure your computer to enable Wake On Lan first. Wake On Lan Help Please refer to the following links to help you get started with Wake On Lan. A mini-tutorial for Windows/Debian:...
当你使用网络时,练习日语或汉字。 This extension was created by Fixoodle, http://www.fixoodle.com, learn from fluent speakers. Characterizer allows you to practice Japanese or Chinese characters while ...
have already learned the theory still sometimes need help remembering how to imple- ment it. The book doesn’t go into depth teaching these concepts. The idea is that you already understand them. ...
02.专四阅读真题讲义(2015年-2018年).pdf
Thus the clients can relatively easily be changed for other types of clients, without need for remembering how was the business logic put together. Using n-tier models also gives other positive side ...
Thus the clients can relatively easily be changed for other types of clients, without need for remembering how was the business logic put together. Using n-tier models also gives other positive side ...
Thus the clients can relatively easily be changed for other types of clients, without need for remembering how was the business logic put together. Using n-tier models also gives other positive side ...
Thus the clients can relatively easily be changed for other types of clients, without need for remembering how was the business logic put together.Using n-tier models also gives other positive side ...
Some codes that are memorable and are worth remembering. 说实话我不会PHP。。。我热爱C++。但是由于工作原因(游戏服务器), 经常需要接入第三方的支付行为以及验证客户端通过第三方进行的登陆行为, 比如...
By combining introductions, overviews, and how-to examples, the In Action books are designed to help learning and remembering.
6.3 Remembering the Current Position... 124 6.4 Accessing the Internal File System... 126 6.5 Accessing SD Cards..... 127 6.6 Fast-Forward >>.....128 CONTENTS 7 III Beyond the Basics 129 7 The ...
- FIX: Improving the process of NGUI remembering the last used values. - FIX: Drag handles will now hide if there is not enough space to draw them. - FIX: Anchors and stretch scripts set to "run only ...