Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Leos924 · Dec 02, 2016 at 11:06 PM · androidandroidpluginfilesandroid-manifestjni

How can I browse files on Android outside of the Unity App folder?

Is there any way to access files in Android with permission from the user?

I think it could be possible using an Android Manifest to require permissions and then access the directories using Native Android Methods but I really don't have any experience programming directly on Android, so I was wondering what is a good point to begin with and if my hypothesis is correct

I already read this Unity manual page: Building Plugins for Android But I don't know if there is something I'm missing, can somebody please tell me what workflow I should follow to accomplish my goal? :)

PS: Excuse me if I commit some grammar or syntax errors but I'm not a native english speaker

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tomekkie2 · Dec 03, 2016 at 06:26 AM 0
Share

You could consider using assets from AssetStore. This is one that I have used: https://www.assetstore.unity3d.com/en/#!/content/151

avatar image Leos924 tomekkie2 · Dec 05, 2016 at 06:03 AM 0
Share

Really I doesn't like too much all the code assets in the Asset Store, because they usually are restricted to some functions and/or I doesn't have enough money yet to afford an asset, I really want to know how to do a native Android plugin without restrictions, so I can handle new features and improvements fast without trying to understand other person's code, but thanks for the suggestion

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by aditya · Dec 03, 2016 at 05:13 AM

Best way to accomplish this is by native Android code and you could do this by native Android plugins... There are lot of tutorials out there on how to create an Android plugin for unity and This Tutorial Here is by far the best i think coz it has nothing to with Android Studio as i m not a big fan of Android Studio ... i know Android Studio helps you with java programming but it has other complications too like gradle and all that... okay, so just follow that tutorial and create an android project and where there you are asked to create a java file just put your own code of accessing android file system (or something like this), just google for code on how to access android directories and you are good to go ... one thin i want to mention here that is not mentioned in tutorial itself is when you reach this line ant jar, then before this just cd your project directory ... for eg, if you created your android project in C:\MyProject path then before ant jar execute cd C:\MyProject so that Apache Ant can find your build.xml

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Leos924 · Dec 05, 2016 at 06:07 AM 0
Share

That tutorial seems very useful, I didn't find anything like that while searching on Google, maybe I didn't use the correct keywords haha Thanks!

avatar image
5

Answer by WoozyBytes · Dec 28, 2016 at 08:39 AM

There's no need to create a plugin for this, you can just use .net System.IO. to create a file browser, and also use Unity's AndroidJavaClass and AndroidJavaObject to call Android Native Methods like Environment.getExternalStorageDirectory to get the path to the user storage for example.

 function GetAndroidExternalStoragePath ()
 {
         var path : String = "";
         try
         {
             var jc : AndroidJavaClass = new AndroidJavaClass("android.os.Environment") ;
             path = jc.CallStatic.<AndroidJavaObject>("getExternalStorageDirectory").Call.<String>("getAbsolutePath");
         }
         catch (e)
         {
           Debug.Log(e.Message);
         }
 }

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gorlog · Apr 03, 2017 at 11:19 PM 1
Share

can u convert to c# pls ?

avatar image Leos924 Gorlog · Apr 03, 2017 at 11:27 PM 1
Share

I think the correct conversion would be:

 public string GetAndroidExternalStoragePath ()
          {
                  string path = "";
                  try
                  {
                      AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment") ;
                      path = jc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory").Call<string>("getAbsolutePath");
 return path;
                  }
                  catch (Exception e)
                  {
                    Debug.Log(e.$$anonymous$$essage);
                  }
          }

avatar image WoozyBytes Gorlog · Apr 13, 2017 at 12:11 PM 0
Share

Leos924 conversion seems correct :)

avatar image TechnoAdiict WoozyBytes · Jul 30, 2017 at 03:27 PM 0
Share

i need to call this function on button click in order to select files from file picker in android ?

Show more comments
avatar image molul · Dec 12, 2017 at 07:45 AM 0
Share

How to reach a public directory in the internal storage? I mean, a directory that's in the same path as DCI$$anonymous$$, Downloads, Android, etc.

avatar image Foxdeimos molul · Oct 04, 2018 at 06:20 PM 2
Share

I know this is late, but if anyone's wondering how to accomplish that, here's the code (In case you want to access the DCI$$anonymous$$ directory, specifically. If not, just change the static property you're passing as the string parameter):

 AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment");
 string path = jc.CallStatic<AndroidJavaObject>("getExternalStoragePublicDirectory", jc.GetStatic<string>("DIRECTORY_DCI$$anonymous$$")).Call<string>("getAbsolutePath");
 
 Debug.Log("Attempting to recover DCI$$anonymous$$ External Storage Directory: " + path);
avatar image tomoaki98 Foxdeimos · Oct 05, 2018 at 08:43 AM 0
Share

Thank you! I've been trying to figure out how can I get the directory to the DCI$$anonymous$$ folder but all the answers so far are either outdated, asking me to use a plug-in or asking to use persistent data for some reason.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to fix lost data with android 1 Answer

Issue with intent filters in AndroidManifest.xml 0 Answers

Unable to retrieve return values from android library (aar file) to c# in unity 5.3.4p3 (string,int,bool) using AndroidJavaClass.Call() 3 Answers

Using AndroidJavaObject.CallStatic to retrieve a return value 0 Answers

Is it possible to block unity's input? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges