Difference between revisions of "Share.share"

From GiderosMobile
Line 22: Line 22:
 
=== Example ===
 
=== Example ===
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
local b = Buffer.new("diploma.jpg")
+
local share = require "Share"
rt:save("|B|diploma.jpg")
+
 
local bdata = b:get()
+
local tex = Texture.new("gfx/cat.jpg")
b = nil
+
local bmp = Bitmap.new(tex)
collectgarbage()
+
local rt = RenderTarget.new(tex:getWidth(), tex:getHeight())
print("DIPLOMA:", #bdata)
+
rt:draw(bmp)
local ok, share = pcall(function() return require "Share" end)
+
local buff = Buffer.new("cat.jpg")
if ok then
+
rt:save("|B|cat.jpg")
-- Analytics("diploma_share")
+
 
share.share("image/jpeg", bdata)
+
local bdata = buff:get()
end
+
 
 +
share.share("image/jpeg", bdata)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
{{Share}}
 
{{Share}}

Revision as of 17:14, 20 February 2025

Available since: Gideros 2020.7
Class: Share

Description

Sharing a piece of data with an external app.

Share.share(mimeType,data)

This invokes the platform default sharing dialog, allowing to save, print, send, share, etc.

Supported MIME types:

  • "text/*"
  • "image/png"
  • "image/jpeg"

Parameters

mimeType: (string) the MIME type of the data
data: (string) the data itself

Example

local share = require "Share"

local tex = Texture.new("gfx/cat.jpg")
local bmp = Bitmap.new(tex)
local rt = RenderTarget.new(tex:getWidth(), tex:getHeight())
rt:draw(bmp)
local buff = Buffer.new("cat.jpg")
rt:save("|B|cat.jpg")

local bdata = buff:get()

share.share("image/jpeg", bdata)