-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAndroidPathManager.cs
More file actions
49 lines (45 loc) · 1.64 KB
/
AndroidPathManager.cs
File metadata and controls
49 lines (45 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using UnityEngine;
using System.IO;
public class AndroidPathManager : MonoBehaviour
{
public static string SampleFilePath
{
get
{
return Path.Combine(GetFriendlyFilesPath(), "Path/To/File");
}
}
public static string SampleCachePath
{
get
{
return Path.Combine(GetFriendlyCachePath(), "Path/To/Cache");
}
}
public static string GetFriendlyCachePath()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject applicationContext = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
AndroidJavaObject path = applicationContext.Call<AndroidJavaObject>("getCacheDir");
string filesPath = path.Call<string>("getCanonicalPath");
return filesPath;
#else
return Application.temporaryCachePath;
#endif
}
public static string GetFriendlyFilesPath()
{
#if UNITY_ANDROID && !UNITY_EDITOR
AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject applicationContext = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
AndroidJavaObject path = applicationContext.Call<AndroidJavaObject>("getFilesDir");
string filesPath = path.Call<string>("getCanonicalPath");
return filesPath;
#else
return Application.persistentDataPath;
#endif
}
}