我正在使用Firebase在Android Studio上开发android应用程序,并且出现以下错误:
[unchecked]未经检查的演员表 必需:OnSuccessListener 找到:乌里
当我单击“显示问题出在哪里”时,我将看到以下代码:
private void uploadImageToFirebaseStorage() {
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null){
profileImageRef.putFile(uriProfileImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
}
下面是整个班级:
public class Profile extends AppCompatActivity {
private static final int CHOOSE_IMAGE = 101;
TextView textView;
EditText editText;
ImageView imageView;
String profileimageurl;
private StorageReference mStorageRef;
Uri uriProfileImage;
FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mStorageRef = FirebaseStorage.getInstance().getReference();
mAuth = FirebaseAuth.getInstance();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
editText =(EditText)findViewById(R.id.nome);
imageView=(ImageView) findViewById(R.id.prefil);
textView=(TextView) findViewById(R.id.textViewVerified);
imageView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
showImageChooser();
}
});
loadUserInformation();
findViewById(R.id.login_bt).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveUserInformation();
}
});
}
@Override
protected void onStart() {
super.onStart();
if(mAuth.getCurrentUser()!=null){
finish();
startActivity(new Intent(this,Login.class));
}
}
private void loadUserInformation() {
final FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
if (user.getPhotoUrl() != null) {
String photoUrl = user.getPhotoUrl().toString();
Glide.with(this)
.load(user.getPhotoUrl().toString())
.into(imageView);
}
if (user.getDisplayName() != null) {
String displayName = user.getDisplayName();
editText.setText(user.getDisplayName());
}
if (user.isEmailVerified()) {
textView.setText("Email verified");
}
else{
textView.setText("Email not Verified(click to Verify");
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(Profile.this,"Verification Email Sent",Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
}
private void saveUserInformation() {
String displayName = editText.getText().toString();
if(displayName.isEmpty()){
editText.setError("Requer Nome");
editText.requestFocus();
return;
}
FirebaseUser user = mAuth.getCurrentUser();
if(user!=null && profileimageurl!=null){
UserProfileChangeRequest profile = new UserProfileChangeRequest.Builder()
.setDisplayName(displayName)
.setPhotoUri(Uri.parse(profileimageurl))
.build();
user.updateProfile(profile)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if( task.isSuccessful()){
Toast.makeText(Profile.this,"Profile Updated",Toast.LENGTH_SHORT).show();
}
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==CHOOSE_IMAGE&& data !=null && data.getData()!=null){
uriProfileImage = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(),uriProfileImage);
imageView.setImageBitmap(bitmap);
uploadImageToFirebaseStorage();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void uploadImageToFirebaseStorage() {
final StorageReference profileImageRef =
FirebaseStorage.getInstance().getReference("profilepics/"+System.currentTimeMillis()+".jpg");
if(uriProfileImage!=null){
profileImageRef.putFile(uriProfileImage)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
profileImageRef.getDownloadUrl().addOnSuccessListener((OnSuccessListener<? super Uri>) uriProfileImage);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Profile.this,e.getMessage(),Toast.LENGTH_SHORT).show();
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menuLogout:
FirebaseAuth.getInstance().signOut();
finish();
startActivity(new Intent(this,Login.class));
break;
}
return true;
}
private void showImageChooser(){
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Escohe a imagem de perfil"),CHOOSE_IMAGE);
}
}