Launching Intent.ACTION_VIEW intent not working on saved image file

前端 未结 4 1247
广开言路
广开言路 2020-12-03 09:07

First of all let me say that this questions is slightly connected to another question by me. Actually it was created because of that.

I have the following code to wr

相关标签:
4条回答
  • 2020-12-03 09:26

    I used this hack to fix error:

    ...
    Uri hacked_uri = Uri.parse("file://" + uri.getPath());
    intent.setDataAndType(hacked_uri, "image/*");
    ...
    
    0 讨论(0)
  • 2020-12-03 09:26

    I used this code for my app and works fine. I only did a litle change.

    I changed This:

    intent.setDataAndType(Uri.parse(posterFile.getAbsolutePath()),"image/*");
    

    For this:

    intent.setDataAndType(Uri.fromFile(posterFile),"image/*");
    
    0 讨论(0)
  • 2020-12-03 09:43

    I decided to create my own Activity which simply draws the image on the screen. It is not a perfect solution but it meets my basic standards... It works :)

    0 讨论(0)
  • 2020-12-03 09:44

    i use this code

     MediaScannerConnection.scanFile(PayamKhosusiActivity.this, new String[] { filez.toString() },
                            null, new MediaScannerConnection.OnScanCompletedListener() {
                                @Override
                                public void onScanCompleted(String path, Uri uri) {
                                    Log.wtf("onScanCompleted", "yes");
    
    
                                    Intent intent = new Intent(Intent.ACTION_VIEW, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                                    intent.setDataAndType(uri, "image/*");
                                    intent.setFlags(FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION); //must for reading data from directory
    
                                    startActivity(intent);
                                }
                            });
    
    0 讨论(0)
提交回复
热议问题