Corona SDK-外部存储(library.getExternalPath)

时间:2018-10-09 04:53:37

标签: plugins lua corona android-external-storage

我一直在用Corona寻找外部android存储,并找到了这个插件:

  

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 .. 因此,为了进行一个没有错误的简单测试,我从电晕中复制了整个示例代码(该代码在system.DocumentsDirectory中创建了一个.txt文件)并与文档的示例代码合并,那么我所有的测试应用程序都是这样:

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”文件夹,并且在我的外部存储中也没有子文件夹,有人可以告诉我我在做什么错吗?我做了很多测试,但没有得到肯定的结果。

0 个答案:

没有答案