0

Good day, all! I'm currently coding a plugin for Unity so that the user can access the file browser and pick an app. Upon picking the app, the file path is supposed to be saved. My code works so far, it's able to get the file path of the file but not the full one.

This is my code so far

int PICKFILE_RESULT_CODE = 1;
@Override
protected void onCreate(Bundle bundle)
{
    super.onCreate(bundle);
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("application/vnd.android.package-archive");
    startActivityForResult(intent, PICKFILE_RESULT_CODE);

 }

@SuppressLint("InlinedApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode==RESULT_OK && requestCode==PICKFILE_RESULT_CODE && data != null)
    {
        String apkPath = data.getData().getPath();

        UnityPlayer.UnitySendMessage("Browser", "OnApkPick", apkPath);
        Browser.this.finish();

        super.onActivityResult(requestCode, resultCode, data);

    }
}

Thanks in advance.

zoenightshade
  • 159
  • 2
  • 12
  • your code is working fine, what exactly you want you are getting the exact path for selected apk. – Nikhil Jadhav Aug 23 '17 at 11:43
  • @NikhilJadhav right now, i'm currently getting "/document/6133-6330:Download/demo.apk" when im trying to select a file from my external storage's download folder. When i try to access my file for upload, it says "Could not find part of path" so i'm wondering how i could modify my code so that i can get the full path of the file. – zoenightshade Aug 24 '17 at 01:36
  • i am getting path as:- /storage/emulated/0/SHAREit/apps/base.apk, and i think its a complete path. if you are not able to upload that file so please check with your final path or else make sure you have given read/write storage permissions/ run time permissions. – Nikhil Jadhav Aug 24 '17 at 05:44
  • @NikhilJadhav yes, that's the path I want to get but i dont know why i'm not getting the right path. im only calling my functions from my plugin to unity and as you can see, the path they're giving me is not the full one. Edit: I also added the permissions in my manifest. – zoenightshade Aug 24 '17 at 06:23
  • if you are using marshmellow or higher version device the please add runtime permissions also – Nikhil Jadhav Aug 24 '17 at 06:31
  • @NikhilJadhav I am currently running my project on my 6.0.1 device. What type of runtime permission exactly? Thanks. x – zoenightshade Aug 24 '17 at 08:01
  • runtime permission for reading and writing the external storage – Nikhil Jadhav Aug 24 '17 at 08:23
  • @NikhilJadhav like this one? https://stackoverflow.com/questions/42110882/get-real-path-from-uri-of-file-in-sdcard-marshmallow – zoenightshade Aug 24 '17 at 09:21

0 Answers0