diff --git a/android/jni/main_native.cpp b/android/jni/main_native.cpp index bf9f992ca8..64f9635bf1 100644 --- a/android/jni/main_native.cpp +++ b/android/jni/main_native.cpp @@ -15,13 +15,13 @@ extern "C" /////////////////////////////////////////////////////////////////////////////////// JNIEXPORT void JNICALL - Java_com_mapswithme_maps_MWMActivity_nativeInit(JNIEnv * env, jobject thiz, jstring path) + Java_com_mapswithme_maps_MWMActivity_nativeInit(JNIEnv * env, jobject thiz, jstring apkPath, jstring storagePath) { jni::InitSystemLog(); jni::InitAssertLog(); LOG(LDEBUG, ("MWMActivity::Init 1")); - GetAndroidPlatform().Initialize(env, thiz, path); + GetAndroidPlatform().Initialize(env, thiz, apkPath, storagePath); LOG(LDEBUG, ("MWMActivity::Init 2")); g_work = new AndroidFramework(); diff --git a/android/jni/platform.cpp b/android/jni/platform.cpp index ea8bc999dd..f7e06a1222 100644 --- a/android/jni/platform.cpp +++ b/android/jni/platform.cpp @@ -4,11 +4,11 @@ #include "../../base/logging.hpp" -void AndroidPlatform::Initialize(JNIEnv * env, jobject activity, jstring path) +void AndroidPlatform::Initialize(JNIEnv * env, jobject activity, jstring apkPath, jstring storagePath) { - m_writableDir = m_resourcesDir = jni::ToString(env, path); - - LOG(LDEBUG, ("Resource path = ", m_resourcesDir)); + m_resourcesDir = jni::ToString(env, apkPath); + m_writableDir = jni::ToString(env, storagePath); + LOG(LDEBUG, ("Apk path = ", m_resourcesDir)); LOG(LDEBUG, ("Writable path = ", m_writableDir)); } diff --git a/android/jni/platform.h b/android/jni/platform.h index bb196e2bd7..eb7f689628 100644 --- a/android/jni/platform.h +++ b/android/jni/platform.h @@ -7,7 +7,7 @@ class AndroidPlatform : public BasePlatformImpl { public: - void Initialize(JNIEnv * env, jobject activity, jstring path); + void Initialize(JNIEnv * env, jobject activity, jstring apkPath, jstring storagePath); virtual void GetFontNames(FilesList & res) const; virtual int CpuCores() const; diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index 8b8dd70714..b8d3cf3a57 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -1,10 +1,16 @@ package com.mapswithme.maps; +import java.io.File; + import com.mapswithme.maps.MainGLView; import com.mapswithme.maps.R; import android.app.Activity; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.os.Bundle; +import android.os.Environment; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -13,12 +19,25 @@ import android.util.Log; public class MWMActivity extends Activity { private static String TAG = "MWMActivity"; + private final static String PACKAGE_NAME = "com.mapswithme.maps"; private MainGLView m_view; - private String getResourcePath() + private String getAppBundlePath() throws NameNotFoundException { - return new String("todo: get data path"); + PackageManager packMgmr = getApplication().getPackageManager(); + ApplicationInfo appInfo = packMgmr.getApplicationInfo(PACKAGE_NAME, 0); + return appInfo.sourceDir; + } + + private String getDataStoragePath() + { + String storagePath = ""; + storagePath = Environment.getExternalStorageDirectory().getAbsolutePath(); + storagePath = storagePath.concat(String.format("/%s", PACKAGE_NAME)); + File f = new File(storagePath); + f.mkdirs(); + return storagePath; } @Override @@ -26,7 +45,14 @@ public class MWMActivity extends Activity { super.onCreate(savedInstanceState); - nativeInit(getResourcePath()); + try + { + nativeInit(getAppBundlePath(), getDataStoragePath()); + } + catch (NameNotFoundException e) + { + e.printStackTrace(); + } m_view = new MainGLView(getApplication()); @@ -77,5 +103,5 @@ public class MWMActivity extends Activity System.loadLibrary("mapswithme"); } - private native void nativeInit(String path); + private native void nativeInit(String apkPath, String storagePath); }