gpt4 book ai didi

java - 调用 user.getPhotoUrl() Firebase 时出现安全异常

转载 作者:行者123 更新时间:2023-11-30 10:01:41 26 4
gpt4 key购买 nike

我目前正在开发一个 Android 应用程序,我必须允许用户使用个人资料图片注册,我能够使用用户名、电子邮件和照片等字段注册用户。当我尝试使用刚刚创建的同一用户重新登录时出现问题,这给了我以下错误....

权限拒绝:从 ProcessRecord 打开提供程序 com.google.android.apps.docs.storagebackend.StorageBackendContentProvider .....................需要您使用 ACTION_OPEN_DOCUMENT 或相关 API 获得访问权限

下面是我创建用户的代码

mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(uname).setPhotoUri(ImgUri).build();

user.updateProfile(profileUpdates);
Toast.makeText(getApplicationContext(), "Registration successful!", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
Intent intent = new Intent(RegisterActivity.this, Login.class);
startActivity(intent);
finish();
}
else {
Toast.makeText(getApplicationContext(), "Registration failed! Please try again later", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});

这是我选择图像的代码

private void chooseImage() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {

ImgUri = data.getData();
System.out.println(ImgUri);

try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), ImgUri);
// Log.d(TAG, String.valueOf(bitmap));

ImageView imageView = findViewById(R.id.userImg);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}

下面是我尝试检索用户个人资料图片时的代码

  FirebaseUser user = mAuth.getCurrentUser();
System.out.println(user.getPhotoUrl());
img.setImageURI(user.getPhotoUrl());

我是否需要将 ImageUri 保存到 Firebase 存储以及 Firebase 实时数据库?或者是否需要任何权限?我需要吗

最佳答案

在拾取图像时为 Intent 添加 Action

private void chooseImage() {
Intent intent=Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"),
PICK_IMAGE_REQUEST);
}

ACTION_OPEN_DOCUMENT is not intended to be a replacement for ACTION_GET_CONTENT. The one you should use depends on the needs of your app:

Use ACTION_GET_CONTENT if you want your app to simply read/import data. With this approach, the app imports a copy of the data, such as an image file.

Use ACTION_OPEN_DOCUMENT if you want your app to have long term, persistent access to documents owned by a document provider. An example would be a photo-editing app that lets users edit images stored in a document provider.

关于java - 调用 user.getPhotoUrl() Firebase 时出现安全异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57309011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com