有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我下载的图像不会出现在我应用程序的屏幕上

这是我的代码:

public class Account_settings extends AppCompatActivity implements View.OnClickListener {
Button cprofile, cstatus, cinfo;
ImageView back;
CircleImageView profile_official;
TextView username, status, info, birth;

FirebaseDatabase database;
DatabaseReference myref;

String uid;
Dialog loading;
private StorageReference imagestorage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_account_settings);
    cprofile = findViewById(R.id.change_pic);
    cstatus = findViewById(R.id.change_status);
    cinfo = findViewById(R.id.change_info);
    back = findViewById(R.id.back58);
    profile_official=findViewById(R.id.profile_image);

    username = findViewById(R.id.display_name);
    status = findViewById(R.id.status);
    info = findViewById(R.id.about);
    birth = findViewById(R.id.birth1);

    uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
    database = FirebaseDatabase.getInstance();
    myref = database.getReference("User_details");
    imagestorage = FirebaseStorage.getInstance().getReference();

    loading = new Dialog(this);
    loading.setContentView(R.layout.custom_dialog);
    loading.setCancelable(true);
    loading.getWindow().setBackgroundDrawableResource(安卓.R.color.transparent);
    loading.show();

    myref.child(uid).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot snapshot) {

            uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
            Userdetails userdetails = snapshot.getValue(Userdetails.class);
            if (userdetails != null) {
                birth.setText(userdetails.getBirth());
                username.setText(userdetails.getName());
                info.setText(userdetails.getInfo_about_me());
                status.setText(userdetails.getStatus());
                Picasso.with(Account_settings.this).load(userdetails.getProfile()).into(profile_official);
            }
            loading.dismiss();
        }

        @Override
        public void onCancelled(@NonNull DatabaseError error) {

        }
    });

    cprofile.setOnClickListener(this);
    cstatus.setOnClickListener(this);
    cinfo.setOnClickListener(this);
    back.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    if (v == back) {
        startActivity(new Intent(getApplicationContext(), Main_page.class));
    }
    if (v == cstatus) {
        String status1 = status.getText().toString();
        Intent intent = new Intent(this, Status_Activity.class);
        intent.putExtra("status_value", status1);
        startActivity(intent);
        finish();
    }
    if (v == cinfo) {
        Intent intent1 = new Intent(this, my_info.class);
        startActivity(intent1);
        finish();
    }
    if (v == cprofile) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);

        startActivityForResult(Intent.createChooser(intent, "Selecting image"), 1); 
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == RESULT_OK) {
        Uri imageUri = data.getData();
        CropImage.activity(imageUri).start(this);
    }
    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { 
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {
            loading.show();

            Uri resultUri = result.getUri();
            StorageReference file_path = imagestorage.child("profile_images").child(uid + ".jpg");
                file_path.putFile(resultUri)
                        .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onSuccess(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
                                final Task<Uri> firebaseUri = taskSnapshot.getStorage().getDownloadUrl();
                                Toast.makeText(Account_settings.this, "Uploaded", Toast.LENGTH_SHORT).show();
                                firebaseUri.addOnSuccessListener(new OnSuccessListener<Uri>() {
                                    @Override
                                    public void onSuccess(Uri uri) {
                                         String downloadUrl = uri.toString();
                                        myref.child("profile").setValue(downloadUrl);
                            }

                        })
                        .addOnFailureListener(new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                loading.dismiss();
                                Toast.makeText(Account_settings.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        });
            }
        });}
        else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
            Exception error = result.getError();
            Toast.makeText(this, "Error! " + error, Toast.LENGTH_SHORT).show();
        }

。 . . . . . . . . . ...........................................................................................................................................................................................................................................................................................................................

我不知道为什么会这样,所以如果有人知道,请帮助我。希望你理解我的代码。 如果你有一个关于存储照片的视频,并在屏幕上显示它们,请发送给我


共 (0) 个答案