Corona - works on simulator but not on real Android device (system.pathForFile)

女生的网名这么多〃 提交于 2019-12-25 03:45:50

问题


I have this simple line of code that works perfectly on the simulator but gets a nil on a actual android device:

local path = system.pathForFile( nil, system.ResourceDirectory)


print('path', path)

path = path .. "/assets/audios"

on the android device I get Runtime Error .......attempt to concatenate local 'path' (a nil value)

I read the the android docs and it says you don't need permission to read the internal storage.

What's causing this error? How to solve it?

Do I need to add any special permissions to use pathForFile in android?


回答1:


Ok..found something that works not the android device. It is bit of a cheat/workaround...but as long as it works....

so this does not work on the device but works on the simulator:

local path = system.pathForFile( nil, system.ResourceDirectory)


print('path', path)

path = path .. "/assets/audios"

This however works which will get you the same result just through different steps:

local path = system.pathForFile('assets/audios/x.wav', system.ResourceDirectory)

    -- path = path .. "/assets/audios"
    path = string.gsub( path, 'x.wav', '' )


来源:https://stackoverflow.com/questions/34633040/corona-works-on-simulator-but-not-on-real-android-device-system-pathforfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!