The brand new error.
I have an image Uri and have permission to open it.
Now i try to open it in native android image viewer.
I already tested few solutions which not worked.
There is a code:
String str_address=getArguments().getString("Path");
FILE_ADRESS= Uri.parse(str_address);
String path = FILE_ADRESS.getPath();
Uri uri = Uri.parse(str_address);
//Uri uri = data.getData();
File file = new File(uri.getPath());//create path from uri
final String[] split = file.getPath().split(":");//split the path.
String filePath = split[1];//assign it to a string(your choice).
String file_type= getActivity().getContentResolver().getType(uri);
imgg.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://"+filePath+file_type.replaceFirst("/",".")), "image/*");
startActivity(intent);
}
});
What i’ve tryied – different versions of data to pass in setDataAndType –
variant with "file://"
<– crushes app
variant with "content://"
<– black screen
variant with direct uri
<– black screen
Currently out of ideas where to fk around to find out.
I’ve catched bug and know that there is something really wrong with the file path, but how to find proper file path for my Uri, possible with file extensions – i don’t really know and the solution i’ve found on internet does not worked :<
>Solution :
A Uri
is not a file. There is no requirement for the user to choose a file on the device, let alone a file whose filesystem path is available to an arbitrary other app.
Replace that with:
String str_address=getArguments().getString("Path");
Uri uri = Uri.parse(str_address);
imgg.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
});