Equ*_*cal 1 android uri google-authentication firebase firebase-authentication
场景:
我正在构建一个允许用户使用他们的Google帐户登录的应用,值得注意的是,这是使用Firebase身份验证完成的.
问题:
用户完美地登录,但每当我得到他们的个人资料图片时,它都会很好地返回,但它非常模糊.
我研究并发现一些网站提到改变谷歌个人资料图片的分辨率,但我不确定这是否可行.我知道Facebook有一个图表,允许你操纵配置文件图像的URL来改变分辨率,但我不知道如何通过谷歌提高配置文件图像的分辨率.
我发布了下面模糊图片的截图:
这是我正在加载配置文件图像的ImageView的XML代码:
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image_view_profile_pic"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="36dp"
android:src="@drawable/app_bar_tool_bar_bg"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFFFF"
android:contentDescription="@string/content_description_profile_picture" />
Run Code Online (Sandbox Code Playgroud)
这是我用来通过Firebase从Google获取个人资料图片的代码:
private void getUserProfileContent() {
// Check if the user is signed in
if (mUser != null) {
for (UserInfo profile : mUser.getProviderData()) {
// Profile photo url
Uri photoUrl = profile.getPhotoUrl();
// Load user's profile photo from their signed-in provider into the image view
Glide.with(ProfileActivity.this)
.load(photoUrl)
.into(mProfilePic);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是获取当前经过身份验证的用户的代码:
// Variable declaration
private FirebaseUser mUser;
// Initializatioin in onCreate method
mUser = FirebaseAuth.getInstance().getCurrentUser();
Run Code Online (Sandbox Code Playgroud)
然后,当然,我在onCreate方法中调用上面的方法,所以它被执行,如下所示:
getUserProfileContent();
Run Code Online (Sandbox Code Playgroud)
我在此网站上看到,可以操纵Google网址来更改图片的大小:
此外,我已经看到这个网站提到类似的配置文件图像模糊:
Firebase Google Group:个人资料图片模糊
由于它与第二个链接有关,我还没有完全理解如何执行他们建议的内容.
我解决了自己的问题,我将详细解释,见下文.
解:
这是上面问题中我方法新修改的代码,这是修复:
private void getUserProfileContent() {
// Check if the user is signed in
if (mUser != null) {
for (UserInfo profile : mUser.getProviderData()) {
// Get the profile photo's url
Uri photoUrl = profile.getPhotoUrl();
// Variable holding the original String portion of the url that will be replaced
String originalPieceOfUrl = "s96-c/photo.jpg";
// Variable holding the new String portion of the url that does the replacing, to improve image quality
String newPieceOfUrlToAdd = "s400-c/photo.jpg";
// Check if the Url path is null
if (photoUrl != null) {
// Convert the Url to a String and store into a variable
String photoPath = photoUrl.toString();
// Replace the original part of the Url with the new part
String newString = photoPath.replace(originalPieceOfUrl, newPieceOfUrlToAdd);
// Load user's profile photo from their signed-in provider into the image view (with newly edited Url for resolution improvement)
Glide.with(ProfileActivity.this)
.load(newString)
.into(mProfilePic);
} // End if
} // End if
}
Run Code Online (Sandbox Code Playgroud)
说明:
代码是自我解释的,但为了清楚地说明许多其他有问题的人,我基本上换掉了我从Google检索到的原始Url部分,它指定了我自己的更高分辨率的图像分辨率.
取而代之的"s96-c/photo.jpg"是"s400-c/photo.jpg"
我在下面的TextViews中提供了一个截图:
从Google检索到的原始网址的网址路径(此网址在其网址中包含s96-c)
我修改过的Url的Url路径(这个url中有s400-c)
从Google上检索的原始网址使用toString()方法调用.这是s96-c屏幕截图中的第三个Url
新修改的Url由我toString()调用它的方法.这是第四个Url(类似于屏幕截图中的第3个Url,此Url 在其Url字符串中有s96-c)
以该顺序
注意:
我想用这个答案做一个深入的解释,因为我想表明即使低分辨率的字符串被高分辨率版本替换,你会注意到最后的TextView显示在其Url s96-c中,而第二个是-last Url(授予你从上到下看)显示完全相同的东西,s96-c
但
分辨率确实提高了,所以我的理论是,即使分辨率提高了,我使用更高的值,谷歌的系统返回了改进的图像,大小为s96-c,无论如何(让我知道是否有人有更具体的理论)
固定模糊度的配置文件图像的屏幕截图(提高了分辨率):
无论如何,你有它,我想显示一个截图与网址和他们的差异,以便我可以解释一切发生的事情,对于任何好奇的人.
我希望这有助于其他许多人,因为模糊的Google用户个人资料图片对我来说是一个非常不方便的问题.
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |