`class BottomSheetDemo : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.bottom_sheet,container)
view.findViewById<Button>(R.id.openButton).setOnClickListener {
captureScreen()
}
return view
}
fun captureScreen(){
val myActivity = activity ?: return
val view = myActivity.window.decorView.rootView
view.isDrawingCacheEnabled = true
view.buildDrawingCache(true)
val bitmap = Bitmap.createBitmap(view.drawingCache)
val file = File(myActivity.cacheDir, "BottomFile.png")
val fOut = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut)
fOut.flush()
fOut.close()
}
}`
I tried the code above, but it’s not working. Can anyone provide some guidance?