Android Question capture screen and share via instagram

trepdas

Active Member
Licensed User
Hello Good People

well, I did find pieces of code to do that but I got mixed up.

can anyone share a simple piece of code to capture the screen and open the share dialog (in order to share the created image) ?

ThXX
 

Alexander Stolte

Expert
Licensed User
Longtime User
I use this to capture a panel with views inside, but i think you can use the activity too, to caputre the complete screen, because the activity is the same as a panel.

capture panel with views inside:
B4X:
Dim v As B4XView = pnl_back
Dim bmp As Bitmap = v.Snapshot

save the bitmap:
B4X:
Sub BytesToFile (Dir As String, FileName As String, Data() As Byte)
   Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
   out.WriteBytes(Data, 0, Data.Length)
   out.Close
End Sub

Public Sub ImageToBytes(Image As B4XBitmap) As Byte()
   Dim out As OutputStream
   out.InitializeToBytesArray(0)
   Image.WriteToStream(out, 100, "JPEG")
   out.Close
   Return out.ToBytesArray
End Sub
and so the call must be:
B4X:
BytesToFile(File.DirInternal, "mytestpic.jpeg",ImageToBytes(bmp))

and then share with Instagram:
you need the "Intentid" lib. from Douglas here
B4X:
Private intent As INTENTID
If intent.IsInitialized = False Then intent.Initialize
  
intent.ShareImageOn_Intent(File.DirInternal,"mytestpic.jpeg","com.instagram.android")

Greetings
 
Upvote 0
Top