Skip to content

Instantly share code, notes, and snippets.

View shiveshmehta09's full-sized avatar
😎
Work Mode On

Shivesh Karan Mehta shiveshmehta09

😎
Work Mode On
View GitHub Profile
/* 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)
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")
}
}
// 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,