PR#101 Adjustments so older API versions save to External Storage

This commit is contained in:
Gergely Hegedus 2022-07-13 15:04:34 +03:00
parent 239f1dd21b
commit 4eda0f9df5
2 changed files with 51 additions and 27 deletions

View file

@ -1,5 +1,6 @@
package org.fnives.test.showcase.android.testutil.screenshot
import android.os.Build
import android.os.Environment
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.runner.screenshot.basicScreenCaptureProcessor
@ -8,5 +9,11 @@ import java.io.File
fun basicScreenCaptureProcessor(subDir: String = "test-screenshots") =
basicScreenCaptureProcessor(File(getTestPicturesDir(), subDir))
@Suppress("DEPRECATION")
fun getTestPicturesDir() =
InstrumentationRegistry.getInstrumentation().targetContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
InstrumentationRegistry.getInstrumentation().targetContext.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
} else {
val packageName = InstrumentationRegistry.getInstrumentation().targetContext.packageName
File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), packageName)
}