【发布时间】:2018-08-17 17:20:10
【问题描述】:
到目前为止,在我的社交媒体应用中,用户的名字、姓氏、电子邮件、性别等数据都可以保存在 firebase 数据库中,并在需要时进行检索。到今天为止,我在第一次创建个人资料时得到了一张有效的个人资料图片,您可以点击空白的个人资料图片图标,它会加载您的图库,用用户选择的任何图片替换它。
虽然这很整洁,但我需要能够以某种方式在我的 firebase 数据库的用户节点下上传这张图片。在转换位图数据时我很迷茫,在阅读了一些文档后,我仍然感到困惑。下面是我使用本地保存的照片替换它作为个人资料图片的代码,以显示我到目前为止所拥有的内容。
@Override
public void onClick(View view)
{
if (view == profilePicture)
{
//Toast.makeText(this, "We made it to the onClick for image!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK)
{
Uri targetUri = data.getData();
Bitmap bitmap;
try
{
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
profilePicture.setImageBitmap(bitmap);
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
onClick 方法在用户点击配置文件图标后运行。现在我将向您展示我目前正在使用的数据库,这是 Firebase 实时数据库,而不是 Firebase 存储。虽然 firebase 存储可能更合适,但我似乎不知道如何判断谁的照片是谁,因为它不会使用与它们关联的用户 ID 上传它们。
【问题讨论】:
标签: firebase firebase-realtime-database firebase-storage user-profile