This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Store taken screenshot into above created path */ | |
fun storeScreenShot(bm: Bitmap?, fileName: String, context: Context?): File { | |
val dir = File(context?.filesDir?.absolutePath) | |
if (!dir.exists()) | |
dir.mkdirs() | |
val file = File(context?.filesDir?.absolutePath, fileName) | |
Timber.d("Create Directory Created : $file") | |
try { | |
val fOut = FileOutputStream(file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
getScreenShotFromView(rootLesson, this@MainActivity) { | |
Timber.d("$it") | |
bitmap = it | |
} | |
} else { | |
bitmap = getScreenShot(rootLesson) | |
Timber.d("Bitmap $bitmap") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for api level 28 | |
fun getScreenShotFromView(view: View, activity: Activity, callback: (Bitmap) -> Unit) { | |
activity.window?.let { window -> | |
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) | |
val locationOfViewInWindow = IntArray(2) | |
view.getLocationInWindow(locationOfViewInWindow) | |
try { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
PixelCopy.request( | |
window, |