Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ACTION_VIEW opens black screen while opening from URI

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);
            }
        });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading