ENOENT (There is no such file or directory) When there is a file

I am trying to share PNG with ShareActionProvider in Android. When I open PNG for Uri, it says that the file was not found. open failed: ENOENT (No such file or directory), although I went into the file system and saw it myself. I tried this on my phone and AVD with a save error. I looked around, but could not find the answers. Any help would be greatly appreciated.

This is where I am trying to open the file:

 File file = new File(getFilesDir()+"wifiqr/", "QRCode.png");
                file.setReadable(true, false);
                Uri uri = Uri.fromFile(file);
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("image/*");
                intent.putExtra(Intent.EXTRA_STREAM,uri);
                provider.setShareIntent(intent);

If this helps here, where I save it:

 String fileName = getFilesDir()+"/wifiqr/" + "QRCode.png";
                etSSID.setText(fileName);
                OutputStream stream = null;
                try {
                    stream = new FileOutputStream(fileName);
                    bmp.compress(Bitmap.CompressFormat.PNG, 80, stream);
                    stream.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

Finally, the error log:

11-15 02:34:43.243      594-892/com.android.mms E/Mms/media: IOException caught while opening or reading stream
        java.io.FileNotFoundException: /data/data/com.frostbytedev.wifiqr/fileswifiqr/QRCode.png: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:416)
        at java.io.FileInputStream.<init>(FileInputStream.java:78)
        at java.io.FileInputStream.<init>(FileInputStream.java:105)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:447)
        at com.android.mms.model.MediaModel.initMediaSize(MediaModel.java:235)
        at com.android.mms.model.MediaModel.<init>(MediaModel.java:74)
        at com.android.mms.model.RegionMediaModel.<init>(RegionMediaModel.java:36)
        at com.android.mms.model.RegionMediaModel.<init>(RegionMediaModel.java:31)
        at com.android.mms.model.ImageModel.<init>(ImageModel.java:73)
        at com.android.mms.ui.SlideshowEditor.changeImage(SlideshowEditor.java:163)
        at com.android.mms.data.WorkingMessage.internalChangeMedia(WorkingMessage.java:640)
        at com.android.mms.data.WorkingMessage.changeMedia(WorkingMessage.java:588)
        at com.android.mms.data.WorkingMessage.setAttachment(WorkingMessage.java:453)
        at com.android.mms.ui.ComposeMessageActivity.addImage(ComposeMessageActivity.java:3150)
        at com.android.mms.ui.ComposeMessageActivity.addAttachment(ComposeMessageActivity.java:3291)
        at com.android.mms.ui.ComposeMessageActivity.access$5900(ComposeMessageActivity.java:167)
        at com.android.mms.ui.ComposeMessageActivity$35.run(ComposeMessageActivity.java:3236)
        at com.android.mms.ui.AsyncDialog$ModalDialogAsyncTask.doInBackground(AsyncDialog.java:129)
        at com.android.mms.ui.AsyncDialog$ModalDialogAsyncTask.doInBackground(AsyncDialog.java:84)
        at android.os.AsyncTask$2.call(AsyncTask.java:287)
        at java.util.concurrent.FutureTask.run(FutureTask.java:234)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at java.lang.Thread.run(Thread.java:856)
        Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Posix.open(Native Method)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
        at libcore.io.IoBridge.open(IoBridge.java:400)
        ... 24 more
+4
source share
2 answers

getFilesDir() (.. ), openFileOutput ( getFilesDir ).

, , .

+2

:

String fileName = getFilesDir()+"/wifiqr/" + "QRCode.png";

"wifiqr/":

File file = new File(getFilesDir()+"wifiqr/", "QRCode.png");

, "/" "wifiqr/" . , getFilesDir() .

, , :

/data/data/com.frostbytedev.wifiqr/fileswifiqr/QRCode.png

, "fileswifiqr".

: , , , , , , .

+1

All Articles