Difference between revisions of "Share:export"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2024.1<br/> '''Class:''' Share<br/> === Description === Exporting a piece of data to the phone via default file application. <syn...")
 
 
Line 4: Line 4:
  
 
=== Description ===
 
=== Description ===
Exporting a piece of data to the phone via default file application.
+
Exporting some data to the phone via default file application.
 
<syntaxhighlight lang="lua">
 
<syntaxhighlight lang="lua">
 
(bool) = Share:export(data,mimeType,filename)
 
(bool) = Share:export(data,mimeType,filename)
Line 12: Line 12:
  
 
=== Parameters ===
 
=== Parameters ===
'''data''': (varies) the data to export (text String or image data)<br/>
+
'''data''': (varies) the data to export (text String or raw data)<br/>
 
'''mimeType''': (string) the MIME type of the exported data<br/>
 
'''mimeType''': (string) the MIME type of the exported data<br/>
'''filename''': (string) the name the file will be saved to<br/>
+
'''filename''': (string) the name the file will be saved with<br/>
  
 
=== Return values ===
 
=== Return values ===
'''Returns''' (boolean) ''true'' if data can be exported<br/>
+
'''Returns''' (boolean) ''true'' if data could be exported<br/>
  
 
=== Examples ===
 
=== Examples ===
Line 26: Line 26:
 
local share = Share.new()
 
local share = Share.new()
  
share:export("Hello Gideros!", "text/plain" , "hello.txt") -- data, MIME type, file name
+
share:export("Hello Gideros!", "text/plain" , "hello.txt") -- data, MIME type, filename
  
 
share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
 
share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
Line 42: Line 42:
 
local rimg = img:read("*all")
 
local rimg = img:read("*all")
  
share:export(rimg, "image/jpeg", "cat1.jpg") -- data, MIME type, file name
+
share:export(rimg, "image/jpeg", "cat1.jpg") -- data, MIME type, filename
 +
 
 +
share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
 +
print("share:export callback:", e and e.status)
 +
end)
 +
</syntaxhighlight>
 +
 
 +
'''Sound'''
 +
<syntaxhighlight lang="lua">
 +
require "Share"
 +
 
 +
local share = Share.new()
 +
 
 +
local data = io.open("audio/Braam - Retro Pulse.wav")
 +
local rdata = data:read("*all")
 +
 
 +
share:export(rdata, "*/*", "snd1.wav") -- data, MIME type, filename
  
 
share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
 
share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)

Latest revision as of 21:05, 20 February 2025

Available since: Gideros 2024.1
Class: Share

Description

Exporting some data to the phone via default file application.

(bool) = Share:export(data,mimeType,filename)

This invokes the platform default file application.

Parameters

data: (varies) the data to export (text String or raw data)
mimeType: (string) the MIME type of the exported data
filename: (string) the name the file will be saved with

Return values

Returns (boolean) true if data could be exported

Examples

Text

require "Share"

local share = Share.new()

share:export("Hello Gideros!", "text/plain" , "hello.txt") -- data, MIME type, filename

share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
	print("share:export callback:", e and e.status)
end)

Image

require "Share"

local share = Share.new()

local img = io.open("gfx/cat.jpg")
local rimg = img:read("*all")

share:export(rimg, "image/jpeg", "cat1.jpg") -- data, MIME type, filename

share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
	print("share:export callback:", e and e.status)
end)

Sound

require "Share"

local share = Share.new()

local data = io.open("audio/Braam - Retro Pulse.wav")
local rdata = data:read("*all")

share:export(rdata, "*/*", "snd1.wav") -- data, MIME type, filename

share:addEventListener(Event.SHARE_EXPORT_RESULT, function(e)
	print("share:export callback:", e and e.status)
end)