博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Remembering Your User 记住你的用户
阅读量:4046 次
发布时间:2019-05-24

本文共 3688 字,大约阅读时间需要 12 分钟。

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 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:

  1. Ask the user to type in a username
  2. Retrieve a unique device ID to remember the device
  3. Retrieve a built-in account from

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 . 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 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 permission. Add a tag in your manifest file to request this permission:

...

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 by calling . Then use that instance to call .

AccountManager am = AccountManager.get(this); // "this" references the current ContextAccount[] accounts = am.getAccountsByType("com.google");

This returns an array of objects. If there's more than one in the array, you should present a dialog asking the user to select one.

Use the Account Object to Personalize Your App

The 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 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.

你可能感兴趣的文章
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>
Selenium-Switch与SelectApi接口详解
查看>>
Selenium-Css Selector使用方法
查看>>
Linux常用统计命令之wc
查看>>
测试必会之 Linux 三剑客之 sed
查看>>
Socket请求XML客户端程序
查看>>
Java中数字转大写货币(支持到千亿)
查看>>
Java.nio
查看>>
函数模版类模版和偏特化泛化的总结
查看>>
VMware Workstation Pro虚拟机不可用解决方法
查看>>
最简单的使用redis自带程序实现c程序远程访问redis服务
查看>>
redis学习总结-- 内部数据 字符串 链表 字典 跳跃表
查看>>
iOS 对象序列化与反序列化
查看>>
iOS 序列化与反序列化(runtime) 01
查看>>
iOS AFN 3.0版本前后区别 01
查看>>
iOS ASI和AFN有什么区别
查看>>
iOS QQ侧滑菜单(高仿)
查看>>
iOS 扫一扫功能开发
查看>>
iOS app之间的跳转以及传参数
查看>>