I am trying to create a personal chatting app which has a button. When click of that button the frame becomes visible which have buttons on click chooser is been created like this. When the image button is clicked it creates the chooser activity after selecting the file I have saved it in imagefile Uri.
But when I try to get the path of the file by using the data.getdata().getpath()
method it gives doument/236
as the output but didn't give the actual path of the file. When I try to use fileutlis to get the path then it says "can't resolve fileutils". Please help me so that I can get the path of my file.
imagesend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checker = "image";
Intent imageIntent = new Intent();
imageIntent.setAction(Intent.ACTION_GET_CONTENT);
imageIntent.setType("image/*");
startActivityForResult(Intent.createChooser(imageIntent,"Select Image"),438);
}
});
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 438 && resultCode == RESULT_OK && data!=null && data.getData()!=null){
loadingBar.setTitle("Sending Message");
loadingBar.setMessage("Please wait...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
imagefile = data.getData();
String filepath = data.getData().getPath();
if(checker.equals("pdf")){
pdfFilemessage();
}else if(checker.equals("image")){
//imagefilemessage();
Toast.makeText(personalChat.this,filepath,Toast.LENGTH_SHORT).show();
}
}
}