Share:export: Difference between revisions
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..." |
No edit summary |
||
| Line 4: | Line 4: | ||
=== Description === | === Description === | ||
Exporting | 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 | '''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 | '''filename''': (string) the name the file will be saved with<br/> | ||
=== Return values === | === Return values === | ||
'''Returns''' (boolean) ''true'' if data | '''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, | 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, | 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 19: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)