尽管调用了 setSelectedAccountName (Android 6.0),但 GoogleAccountCredential 名称为空 [英] GoogleAccountCredential name is null despite calling setSelectedAccountName (Android 6.0)

查看:35
本文介绍了尽管调用了 setSelectedAccountName (Android 6.0),但 GoogleAccountCredential 名称为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用安全后端创建了一个端点,并且自 3 月以来一直在我正在构建的应用程序上使用它(源文档 此处).我最近在我的 Android 6.0 设备上安装了最新版本,并弹出了一个奇怪的错误(它在 4.2.2 和 5.1 上完美运行).

I've created an endpoint using a secured backend and have been using it since March on an app I'm building (source docs here). I recently installed the latest version to my Android 6.0 device and an odd error popped up (it works perfectly on 4.2.2 & 5.1).

具体的错误是:

IllegalArgumentException: the name must not be empty: null 

我追踪到凭证错误,您可以看到下面的代码.在 Android 6.0 上,帐户可能是user@gmail.com",但字符串 'test' 结果为空!

Which I traced to an error with the credential, you can see the code below. On Android 6.0 account may be "user@gmail.com" but the string 'test' turns out to be null!

6.0 是否有什么特定的地方改变了 GoogleAccountCredential?

Is there something specific about 6.0 that changed GoogleAccountCredential?

public static GoogleAccountCredential getCredential(Context ctx) {

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    String account = prefs.getString(UserProfileHelper.PREF_USER_ACCOUNT, "");
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(ctx,
            "server:client_id:MY_ACCOUNT_NUMS.apps.googleusercontent.com")
            .setSelectedAccountName(account);


    String test = credential.getSelectedAccountName();
    return credential;
}

推荐答案

是的,对于 Android 6.0 Marshmallow,您现在需要在运行时请求权限 https://developer.android.com/training/permissions/index.html

Yes with Android 6.0 Marshmallow, you will now need to request permissions at run time https://developer.android.com/training/permissions/index.html

为了获得这些凭据,您需要在 CONTACTS 组中拥有 GET_ACCOUNTS 权限

In order to get those credentials you need the GET_ACCOUNTS permission in the CONTACTS group

https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous

您必须在您的活动/片段中请求它并处理与您的应用相关的任何用户体验.

You will have to request it in your activity/fragment and handle any UX pertaining to your app.

这篇关于尽管调用了 setSelectedAccountName (Android 6.0),但 GoogleAccountCredential 名称为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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