Android:获取用户ID不需要可怕的(用户权限)吗? [英] Android: get user ID without requiring scary (for user) permissions?

查看:183
本文介绍了Android:获取用户ID不需要可怕的(用户权限)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了管理用户首选项,目前,我要获取google用户名(实际上是他们已注册到设备的电子邮件地址),并使用该用户名(的哈希值)作为用户ID"来区分不同的用户. 此处.

In order to manage user preferences, at present I'm grabbing the google user name (effectively the email address they've registered to the device) and using (a hash of) that as a "user ID" to distinguish between different users. Something along the lines of what is described here.

一切正常,但是(似乎可以理解)一些用户的许可似乎使该应用有一定的邪恶力量来拖曳其帐户信息或联系人,这使用户感到震惊.

That all works fine, but some users are (understandably) scared off by any permission that seems to give the app some evil power to trawl through their account info or contacts.

Google现在实施运行时权限中的="noreferrer">权限组模式.他们已将GET_ACCOUNTS放入CONTACTS权限组.因此,现在,为了生成唯一的匿名用户ID,必须向用户显示一个对话框,该对话框显示:

this issue is even more acute with the way in which Google has now implemented Permission Groups in the Android 6 runtime permission schema. They have put GET_ACCOUNTS into the CONTACTS permission group. So now, in order to generate a unique anonymous User ID, the user has to be presented with a dialog that says:

允许该应用访问您的联系人吗? |拒绝|允许|

Allow this app to access your contacts? | Deny | Allow |

那是多么令人误解的??我的应用程序不希望访问联系人,但是系统要求用户授予该应用程序访问联系人的权限!是的,有机会用一个单独的对话框向用户解释,实际上,不需要访问联系人,但是他们仍然会得到一个库存系统对话框,要求他们授予访问联系人的权限……自然,他们会认为如果不需要访问联系人,为什么会要求我授予此权限?"和我真的信任开发人员吗?他们说不需要联系,但这是真的吗?" ...非常非常混乱,用户体验非常差,恕我直言(以及

How misleading is that?? My app has no wish to access contacts, but the user is being asked to grant permission for the app to access contacts! Yes, there is an opportunity to explain to the user with a separate dialog that, in fact, access to contacts is NOT required, but then they still get the stock system dialog that asks them to grant permission to access contacts... naturally they will think "why am I being asked to grant this permission if access to contacts is not required?" and "do I really trust the developer? they say access to contacts is not required, but is that really true?"... very very confusing and a very poor user experience IMHO (and the opinion of others too).

我宁愿避免所有这些麻烦和混乱并获得唯一的用户ID,而无需特殊的权限.

I'd rather just avoid all of this hassle and confusion and obtain a unique user ID without special permissions being required.

SDK中是否有一个库存函数或方法可以在不需要任何其他许可的情况下为用户返回唯一的用户ID?如果没有的话,我会感到很惊讶,因为想要做一个拥有管理应用程序用户的用户ID的事情似乎很普遍.

So is there a stock function or method in the SDK that will return a unique user ID for the user, without requiring any additional permission? I'm kinda surprised if there isn't, because it would seem to be quite a common thing to want to do... to have a user ID for managing app users.

两点:

(a)我只需要一个匿名用户ID ...实际上不需要用户的电子邮件地址,也永远不需要用户的电子邮件地址.因此,我无法理解为什么Google无法提供getUserID()方法来返回唯一的匿名ID,而不必授予该应用特殊权限.

(a) I only need an anonymous user ID... I don't actually need the user's email address, nor would I ever want the user's email address. So I can't see why google can't provide a getUserID() method that returns a unique anonymised ID, without having to grant special permissions to the app.

(b)必须是用户ID,而不是设备ID,这样它才能在注册到同一Google帐户的所有用户设备上正常工作.

(b) It has to be a user ID, not a device ID, so that it will work across all of the user's devices registered to the same google account.

谢谢.

推荐答案

如果您使用Google Play服务,则无需任何额外权限即可获取帐户类型和帐户名称.

If you use Google Play Services you can get the account type and account name without any extra permissions.

首先,将以下依赖项添加到build.gradle:

First, add the following dependency to build.gradle:

compile 'com.google.android.gms:play-services-auth:8.4.0'

接下来,启动帐户选择器意图:

Next, launch the account chooser intent:

Intent intent = AccountPicker.newChooseAccountIntent(null, null,
    new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
    false, null, null, null, null);

try {
  startActivityForResult(intent, REQUEST_CODE_EMAIL);
} catch (ActivityNotFoundException e) {
  // This device may not have Google Play Services installed.
  // TODO: do something else
}

最后,覆盖

Finally, override onActivityResult to get the account type and account name:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == REQUEST_CODE_EMAIL && resultCode == RESULT_OK) {
    String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
    String accountType = data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE);
    // TODO: do something with the accountName
    return;
  }
  super.onActivityResult(requestCode, resultCode, data);
}


来源: https://stackoverflow.com/a/19444640/1048340

这篇关于Android:获取用户ID不需要可怕的(用户权限)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆