【问题标题】:Getting the android username stored in the phone获取存储在手机中的android用户名
【发布时间】:2012-01-01 03:18:05
【问题描述】:

我正在编写一个需要从手机中检索 android 用户名 username@gmail.com 的应用程序。我一直在看 AccountManager 类。这就是我现在在我的代码中的内容。

    AccountManager accountManager = AccountManager.get(this);

    Account[] accounts =
    accountManager.getAccountsByType("com.google");

    String email="";
    email=accountManager.getUserData(accounts[0], accountManager.KEY_USERDATA);

但是,我得到的调用者 uid 10085 与验证者的 uid 异常不同。 有人知道怎么做吗?

PS。我不需要密码或身份验证令牌,我只需要用户名。

【问题讨论】:

    标签: android


    【解决方案1】:

    用户名可供您使用;只需使用:

    String email = accounts[0].name;

    【讨论】:

      【解决方案2】:

      您的清单文件中是否设置了GET_ACCOUNTS 权限?请参阅 getAccountsByType() 方法上的docs

      此方法需要调用者持有GET_ACCOUNTS权限。

      确保您的应用程序清单有这一行:

      <uses-permission android:name="android.permission.GET_ACCOUNTS" />

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多