Remembering Your User 记住你的用户
来源:互联网 发布:php源码加密方法 编辑:程序博客网 时间:2024/04/28 04:36
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 queryAccountManager
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 ofAccountManager
by calling AccountManager.get()
. Then use that instance to callgetAccountsByType()
.
AccountManager am = AccountManager.get(this); // "this" references the current ContextAccount[] accounts = am.getAccountsByType("com.google");
This returns an array of Account
objects. If there's more than oneAccount
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.
- Remembering Your User 记住你的用户
- 跟随你的用户(Follow Your User)
- 记住:用户不是傻*,她是你的老婆大人
- 如何能让用户记住你的网站?
- 记住密码的用户登录
- 你值得记住的名言
- 怎样通过差异化定位,让用户记住你?
- jsp Cookie记住用户的登录状态
- cookie:记住用户登录时的用户名
- cookie:记住用户登录时的用户名
- 用户登录记住密码功能的实现
- 用户登录记住密码----SharedPreferences的使用
- 记住能救你命的知识!!
- 记住,倍增你的学习力
- 记住、坚持下来就是你的资本
- 程序员,请记住你手下的责任
- 程序员,请记住你手下的责任
- 你要永远记住的那些话
- Flex开源项目 (整合)
- set autotrace on explain异常:SP2-0613: Unable to verify PLAN_TABLE format or existence
- Remaining Backward Compatible 保持向后兼容
- 二分查找实现
- 解决花生壳80端口问题
- Remembering Your User 记住你的用户
- WPS:一键加密
- VB.Net视频总结
- java中XML格式的字符串解析
- 堆排序实现
- Authenticating to OAuth2 Services 验证OAuth2服务
- ubuntu中打开终端的方法
- 修改PHP上传文件大小限制
- 【python】为何用/usr/bin/env