Corona sdk - внешнее хранилище (library.getExternalPath) - PullRequest
0 голосов
/ 09 октября 2018

Я искал внешнее хранилище для Android с Corona и нашел этот плагин:

https://marketplace.coronalabs.com/corona-plugins/android-file-and-uri-manager

Его документация находится на этом сайте:

http://cnksoft.es/index.php/otro-software/9-plugin-cnkfilemanager-for-corona

В Github есть даже несколько собственных проектов, но он не имеет эксклюзивного использования library.getExternalPath .. поэтому для проведения простого теста вкоторый не мог быть ошибкой, я скопировал весь пример кода из короны (код, в котором он создает файл .txt в system.DocumentsDirectory) и объединил с примером кода документации, тогда ВСЕ мое тестовое приложение это:

local library = require "plugin.cnkFileManager"

------- CODE CORONA SAMPLE
-- Get path for file "data.txt" in the documents directory
local path = system.pathForFile( "data.txt", system.DocumentsDirectory )

-- Open the file from the path
local fh, reason = io.open( path, "r" )

if fh then
    -- File exists; read its contents into a string
    local contents = fh:read( "*a" )
    print( "Contents of " .. path .. "\n" .. contents )

else
    -- File open failed; output the reason
    print( "File open failed: " .. reason )

    -- Create file since it doesn't exist yet
    fh = io.open( path, "w" )

    if fh then
        print( "Created file" )
    else
        print( "Create file failed!" )
    end

    local numbers = { 1,2,3,4,5,6,7,8,9 }
    fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" )

    for _,v in ipairs( numbers ) do
        fh:write( v, " " )
    end

    fh:write( "\nNo more data\n" )
end
-----------------------------

----------------------------------------- Code Plugin cnkFileManager for Corona
local function listener (event)

    if event.done == "ok" then
        print ("ok")
    else
        print ("ERROR ", event.error)
    end

end


library.getExternalPath (
{
listener = listener,
mainFolder = "NovaPastaT",
subFolder = "miPASTA",
isPublic = true,
isRemovable = false,
file = 
{
    { filename="data.txt", baseDir=system.DocumentsDirectory },
},
})


io.close( fh )

--native.showAlert( "FOMT", library.getExternalPath, { "OK" } )   FAILED TEST
print( path )

Мои настройки сборки:

--
-- For more information on build.settings, see the Project Build Settings guide at:
-- https://docs.coronalabs.com/guide/distribution/buildSettings
--

settings =
{
    orientation =
    {
        -- Supported values for orientation:
        -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight
        default = "portrait",
        supported = { "portrait", },
    },

    --
    -- Android section
    --
    android =
    {
        usesPermissions =
        {
            "android.permission.INTERNET",
            "android.permission.WRITE_EXTERNAL_STORAGE",
            "android.permission.INSTALL_PACKAGES",
            "android.permission.READ_EXTERNAL_STORAGE",
        },
    },

    --
    -- iOS section
    --
    iphone =
    {
        xcassets = "Images.xcassets",
        plist =
        {
            UIStatusBarHidden = false,
            UILaunchStoryboardName = "LaunchScreen",
        },
    },

    --
    -- Plugins section
    --
    plugins =
    {
        ['plugin.cnkFileManager'] = {publisherId = 'es.cnksoft'},
    },

    --
    -- Project section
    --
    excludeFiles =
    {
        -- Exclude unnecessary files for each platform
        all = { "Icon.png", "Icon-*dpi.png", "Images.xcassets", },
        android = { "LaunchScreen.storyboardc", },
    },
}

Теперь, следуя логике документации, она должна была работать, но она просто не создает папку "NovaPastaT" и неподпапка в моем внешнем хранилище, кто-нибудь может сказать мне, что я делаю не так?Я сделал много тестов и не могу получить положительный результат.

...