0

I am working in Unity, and I am using intent so my app would receive the file path of the file that I used to launch my app which in this case is a .CSV file.

AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

    AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");

This is how I get the data path.

string result = intent.Call<string>("getDataString");

This is the path it gives:

file:///storage/emulated/0/map4.csv

The path I need:

/storage/sdcard0/map4.csv

Otherwise I can't acces the file on that path.

How could I get the 2nd type of path?

HP Addict
  • 3
  • 1
  • It may be a permissions issue [Reference Link](https://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed) . You may need to add the read files permission in the manafest or Grand read on the intent like "intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);" – David Feb 11 '19 at 20:01
  • The problem is that actual path doesn't work, only relative path – HP Addict Feb 11 '19 at 20:27
  • It doesn't seem to be permission related, as I get a path, but I believe this to be an issue with the method. A different method should be called for getting the path. But I have tried every path related method. – HP Addict Feb 11 '19 at 20:31
  • Interesting, maybe [Reference Link 2](https://stackoverflow.com/questions/15841380/android-disambiguating-file-paths) and using the getCanonicalPath() method? – David Feb 11 '19 at 20:55
  • It is all good now. Problem was that it replaces % with %20 and so on, needed to decudeURL – HP Addict Feb 11 '19 at 21:15
  • How did the path get URL encoded? – David Feb 11 '19 at 21:33
  • result = WWW.UnEscapeURL(result); Where result is the Path – HP Addict Feb 12 '19 at 12:48

1 Answers1

0

The Android Documentation link shows:

getDataString()
    "The same as getData(), but returns the URI as an encoded String."

So it makes sense to need to "WWW.UnEscapeURL(result)"

David
  • 231
  • 1
  • 8