Writable path problem

Hey guys,

I’m trying to save an image with RenderTexture to a subfolder of the defualt writable path of the current operating system. Let me explain that with an example:

Default writable path is data/data/com.example.app/files for Android and I want to save my image in a folder named test. To do that I’m calling

RenderTexture* renderTexture = RenderTexture::create(or something like that)
FileUtils::getInstance()->setWritablePath(“data/data/com.example.app/files/test”);
renderTexture->saveToFile(“an_image.png”);

This works ok in iOS (of course the above "data/data/com.example.app/files" path is different in iOS platform) but in Android, it looks like setWritablePath method does not have any affect. While getWritablePath() calling a JNI method to return a string, setWritablePath() just sets an instance variable.

void FileUtils::setWritablePath(const std::string& writablePath)
{
_writablePath = writablePath;
}

string FileUtilsAndroid::getWritablePath() const
{
// Fix for Nexus 10 (Android 4.2 multi-user environment)
// the path is retrieved through Java Context.getCacheDir() method
string dir("");
string tmp = JniHelper::callStaticStringMethod(“org/cocos2dx/lib/Cocos2dxHelper”, “getCocos2dxWritablePath”);
if (tmp.length() > 0)
{
dir.append(tmp).append("/");
return dir;
}
else
{
return “”;
}
}

Am I missing something here? As I said, this works as expected under iOS platform. Can anyone explain me how to perform this action please? Btw I’m using cocos2d-x v3.15 with Android Studio.

I don’t think you need to set the path. You don’t know even if there are proper permissions to it.

Use what getWriteablePath() returns. Or use some JNI to check for an SDCard or what not to store files on.