Muddz / QuickShot

[Moved to MavenCentral] Capture images of any View, SurfaceView or Bitmap from your Android app in: .jpg .png or .nomedia with simple oneliner codes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FileNotFoundException on Emulator

AbhinayMe opened this issue · comments

here is the logcat. This only happens on emulator. Device works fine.

W/System.err: java.io.FileNotFoundException:myapp/screenshots/1580444203567.png (No such file or directory)
W/System.err: at java.io.FileOutputStream.open0(Native Method)
W/System.err: at java.io.FileOutputStream.open(FileOutputStream.java:287)
W/System.err: at java.io.FileOutputStream.(FileOutputStream.java:223)
W/System.err: at java.io.FileOutputStream.(FileOutputStream.java:171)
W/System.err: at com.muddzdev.quickshot.QuickShot$BitmapSaver.save(QuickShot.java:245)
W/System.err: at com.muddzdev.quickshot.QuickShot$BitmapSaver.doInBackground(QuickShot.java:315)
W/System.err: at com.muddzdev.quickshot.QuickShot$BitmapSaver.doInBackground(QuickShot.java:214)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:333)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)

@AbhinayMe Please post the code, library version number, SDKmin number

minSdkVersion 23
targetSdkVersion 29

Emulator version: 8.1.0

& Here is the code

        String filepath = "myapp/screenshots";
        QuickShot
                .of(ssView)
                .setPath(filepath)     //  Path defaults to /Pictures in the public storage.
//                        .setFilename(filename)              //  Filename defaults to a timestamp.
                .toPNG()                            //  Image format defaults to .JPG
                .setResultListener(new QuickShot.QuickShotListener() {
                    @Override
                    public void onQuickShotSuccess(String path) {
                        Log.d(TAG, path);
                        shareOnWhatsApp(path);
                    }

                    @Override
                    public void onQuickShotFailed() {
                        Toast.makeText(mContext, "Sorry, Failed to save screenshot.", Toast.LENGTH_SHORT).show();
                    }
                })
                .save();

Screenshot_1580696740
Screenshot_1580696761

Have you set your path to myapp/screenshots/1580444203567.png
Post the actual path and filename

Yes, File name is commented so it takes default. But the path is correct.

String filepath = "myapp/screenshots";

@AbhinayMe I will take a look at it with the same configuration and emulator.

The solution to your problem is to specificy the full path in the device storage:

String filepath = Environment.getExternalStorageDirectory() + File.separator + "myapp/screenshots";

Here we are saving to the public storage. In QuickShot the client of the library is fully responsible for the full path.

Here we are saving to the public storage. In QuickShot the client of the library is fully responsible for the full path. - it seems like this isn't true.

I'm having to implement conditional behavior based on API level because on Q quickshot prepend /Pictures to any path I provide it.

@athornz I will take a look at it.

I feel like the library shouldn't have any special handling of the storage path if the user specifies one. Or alternatively have a setAbsolutePath and setRelativePath method where the user can choose.

I'd like to be able to pass in an absolute path and have that path returned in the callback of the saved screenshot.

@athornz

The library checks if the app is Android Q or below and handles the saving process differently due to Android's new Scooped Storage system.

If you app is Android Q or above, it will use this method and the root path must always be ./Pictures (Environment.DIRECTORY_PICTURES) when you save images to the public storage space. Else you will get an error. That is why any path always will be relative to ./Pictures

Anything below Android Q is does not follow this rule and you are free to use any path

If no path is specified then QuickShot will always default to ./Pictures regardless of API level or filename