I have tested this on an Android 7.0 device only - take a screenshot of your activity. You need to enable the JavaObject library to make use of it.
@JordiCP solved my initial problem here (thanks @JordiCP):
https://www.b4x.com/android/forum/t...tivity-to-inline-java-code.86796/#post-549360
You need to handle the returned bitmap in your B4A code (i.e saving it, etc, etc, .....)
Sample Code:
@JordiCP solved my initial problem here (thanks @JordiCP):
https://www.b4x.com/android/forum/t...tivity-to-inline-java-code.86796/#post-549360
You need to handle the returned bitmap in your B4A code (i.e saving it, etc, etc, .....)
Sample Code:
B4X:
#Region Project Attributes
#ApplicationLabel:b4aTakeScreenshot
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim nativeMe As JavaObject
Private Button1 As Button
Private iv1 As ImageView
Private bm As Bitmap
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
nativeMe.InitializeContext
bm.Initialize(File.DirAssets,"a.png")
iv1.Bitmap = bm
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
bm = nativeMe.RunMethod("takeScreenshot", Array(nativeMe)) 'YOU NEED TO HANDLE THE BITMAP FROM HERE ONWARDS.....
iv1.Bitmap = bm
End Sub
#If Java
import android.app.Activity;
import android.graphics.Bitmap;
import android.view.ViewGroup;
public static Bitmap takeScreenshot(Activity activity) {
ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
decorChild.setDrawingCacheEnabled(true);
decorChild.buildDrawingCache();
Bitmap drawingCache = decorChild.getDrawingCache(true);
Bitmap bitmap = Bitmap.createBitmap(drawingCache);
decorChild.setDrawingCacheEnabled(false);
return bitmap;
}
#End If