public void fileSearching(){
try{
// find1, find2 are buttons that open the file explorer
find1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
check = 0;
startActivityForResult(i, CODE);
}
});
find2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
check = 1;
startActivityForResult(i, CODE);
}
});
}
catch (Exception ex){}
}
@Override
public void onActivityResult(int request, int result, Intent data){
if (request == CODE && result == RESULT_OK){
Uri u = data.getData();
String path = data.getData().getPath();
}
}
Retrurns /external/file/59 but i need /sdcard/downloads/... + file name
I need this because i want to get a sha-1,md5,... hash for any file.
If i use the "/external/file/xx" it gives me a FileNotFoundException.
I've tried some solutions that were already presented but none seemed to work for me or i didn't know how to use it
That is because you did not look at the scheme of the
Uri
.getPath()
only has meaning if the scheme isfile
. You will rarely get aUri
with afile
scheme. Usually, it will have acontent
scheme, in which case the path is meaningless to you.Use
ContentResolver
andopenInputStream()
to get anInputStream
on the content identified by theUri
. Pass thatInputStream
to your hashing algorithm.