Game Development Reference
In-Depth Information
4.
Check if the storage is writable:
try
{
new File( ExternalStoragePrefix ).mkdirs();
File F = new File(
ExternalStoragePrefix + "/engine.log" );
F.createNewFile();
F.delete();
}
catch (IOException e)
{
Log.e( "App6", "Falling back to internal storage" );
ExternalStoragePrefix = this.getDir(
getApplication().getPackageName(), MODE_PRIVATE
).getPath();
}
5.
Pass the path to our C++ code:
OnCreateNative( ExternalStoragePrefix );
public static native void OnCreateNative(String
ExternalStorage);
How it works...
Native code implements the JNI call OnCreateNative() this way:
extern std::string g_ExternalStorage;
extern "C"
{
JNIEXPORT void JNICALL
Java_com_packtpub_ndkcookbook_app6_App6Activity_OnCreateNative(
JNIEnv* env, jobject obj, jstring Path )
{
g_ExternalStorage = ConvertJString( env, Path );
OnStart();
}
}
There is also a small helper function to convert Java strings to std::string , which we will
use frequently:
std::string ConvertJString(JNIEnv* env, jstring str)
{
 
Search WWH ::




Custom Search