Android Question Take a Screenshot full activity

klingon467

Member
Licensed User
Longtime User
Hi at all,
i see this old topic: https://www.b4x.com/android/forum/threads/take-screenshot-in-b4a-version-2-0.18820/
and i trying to create a android app with this function but i using service module and i want capture other activity on phone
i have modify the function so:
B4X:
Sub TakeScreenshot
    Log("TakeScreenshot activated")
       ' Take a screenshot.
     Dim c As Canvas
     Dim Obj1, Obj2 As Reflector
     Dim now As Long
     Dim dt As String
      Try
     
       DateTime.DateFormat = "yyMMddHHmmss"
       now = DateTime.now
       dt = DateTime.date(now) ' e.g.: "110812150355" is Aug.12, 2011, 3:03:55 p.m.
       Obj1.Target = Obj1.GetActivityBA
       Obj1.Target = Obj1.GetField("vg")
     
       c.Initialize2(bmp)
       Dim args(1) As Object
       Dim types(1) As String
       Obj2.Target = c
       Obj2.Target = Obj2.GetField("canvas")
       args(0) = Obj2.Target
       types(0) = "android.graphics.Canvas"
       Obj1.RunMethod4("draw", args, types)
       Dim Out As OutputStream
       Out = File.OpenOutput(File.DirRootExternal, dt & ".png", False)
       bmp.WriteToStream(Out, 100, "PNG")
       Out.close
       Catch
       Log(LastException.Message)
       End Try
End Sub

B4X:
Sub Service_Create
bmp.InitializeMutable(480dip, 350dip)

.....
end sub

B4X:
Sub Process_Globals
  Dim bmp As Bitmap
End sub

for using i call TakeScreenshot function but i recived a error:
TakeScreenshot activated
java.lang.NullPointerException

thanks
 
Top