概要
UnityEngine.Application.persistentDataPath
と同様の文字列を返す関数を自作してみる
ソースコード
using UnityEngine; public static class AndroidUtils { public static string GetExternalFilesDir() { using ( var player = new AndroidJavaClass( "com.unity3d.player.UnityPlayer" ) ) using ( var activity = player.GetStatic<AndroidJavaObject>( "currentActivity" ) ) using ( var file = activity.Call<AndroidJavaObject>( "getExternalFilesDir", null ) ) { if ( file == null ) return string.Empty; return file.Call<string>( "getAbsolutePath" ); } } }
使用例
using UnityEngine; public class Test : MonoBehaviour { private void Awake() { Debug.Log( AndroidUtils.GetExternalFilesDir() ); } }
/storage/emulated/0/Android/data/【パッケージ名】/files