Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. static string GetDataFilePath()
  2. {
  3. #if UNITY_ANDROID && !UNITY_EDITOR
  4. try
  5. {
  6. System.IntPtr contextWrapper = AndroidJNI.FindClass("android/content/ContextWrapper");
  7. System.IntPtr contextWrapperGetFilesDir = AndroidJNIHelper.GetMethodID(contextWrapper, "getFilesDir", "()Ljava/io/File;");
  8.  
  9. using (AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
  10. {
  11. using (AndroidJavaObject unityPlayerCurrentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
  12. {
  13. System.IntPtr unityPlayerCurrentActivityRawObject = unityPlayerCurrentActivity.GetRawObject();
  14. System.IntPtr filesDir = AndroidJNI.CallObjectMethod(unityPlayerCurrentActivityRawObject, contextWrapperGetFilesDir, new jvalue[0]);
  15.  
  16. System.IntPtr file = AndroidJNI.FindClass("java/io/File");
  17. System.IntPtr fileGetAbsolutePath = AndroidJNIHelper.GetMethodID(file, "getAbsolutePath", "()Ljava/lang/String;");
  18. string absolutePath = AndroidJNI.CallStringMethod(filesDir, fileGetAbsolutePath, new jvalue[0]);
  19.  
  20. return absolutePath;
  21. }
  22. }
  23. }
  24. catch (System.Exception e)
  25. {
  26. Debug.Log(e.ToString());
  27. return Application.persistentDataPath;
  28. }
  29. #else
  30. return Application.persistentDataPath;
  31. #endif
  32. }
  33.  
  34. public GetPath GetPathScript;
  35. string Path = $"{GetPathScript.GetDataFilePath()}/{fileName}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement