我正在尝试通过从手机的图片库中选择图片来上传图片。但是,选择它后根本不执行任何操作,甚至不上传它。
我尝试清理构建并重新构建仍然没有帮助。
它会自动断开:
V / FA:已在尝试连接D / FA:已连接到远程 服务V / FA:处理排队的服务任务:2 V / FA:不活动, 与服务断开连接
public class MainActivity extends AppCompatActivity {
Button uploadButton;
ImageView downloadedImage;
private static final int CAMERA_REQUEST_CODE=1;
private StorageReference storageReference;
//private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uploadButton = findViewById(R.id.button);
downloadedImage = findViewById(R.id.imageView);
storageReference = FirebaseStorage.getInstance().getReference();
//progressDialog = new ProgressDialog(this);
uploadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent,CAMERA_REQUEST_CODE);
Log.i("Done","Till here");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_REQUEST_CODE && requestCode == RESULT_OK)
{
Log.i("Not Done","This log is not visible");
Uri uri = data.getData();
StorageReference filepath = storageReference.child("Photo").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//progressDialog.dismiss();
Toast.makeText(MainActivity.this,"Uploaded...",Toast.LENGTH_LONG).show();
}
});
}
}
}
我得到的错误是:
I / art:拒绝对先前失败的类进行重新初始化 java.lang.Class: java.lang.NoClassDefFoundError:无法解决以下问题: Landroid / view / View $ OnUnhandledKeyEventListener;
答案 0 :(得分:0)
在&&之后将requestCode更改为resultCode,它将起作用。
if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK)
{
}