0

I'm building an Android app that needs to be able to go thru file explorer and pick a file. as of now, have a button (that doesn't do anything yet) from app > res > menu > main.xml but I need pressing it to take my to the file explorer, from which a user can chose a file that ultimately will be uploaded.

How and where should I code this, both in xml and java? I've looked online, but most Google search results with "file explorer" and "android studio" in the query return posts about people using file explorer on their emulator more than integrating it's use into the app.

perhaps I should've added that I want a menu button to do it, and with the latest dev tools.

edit: here's my logcat file (tho I moved the functionality to a new button instead of a menu drop down and edited out my name and project name).

click the link to see text from logcat

Jerry00
  • 3
  • 3
  • Here were the top two google results for "java android select file to upload".. http://stackoverflow.com/questions/7856959/android-file-chooser and http://stackoverflow.com/questions/9923760/how-to-use-intent-for-choosing-file-browser-to-select-file ... Both of these appear to aid your situation. – Kade M. Apr 04 '17 at 04:30
  • Possible duplicate of [How to use intent for choosing file browser to select file](http://stackoverflow.com/questions/9923760/how-to-use-intent-for-choosing-file-browser-to-select-file) – Kindle Q Apr 04 '17 at 04:41

1 Answers1

0

You can use something like this in the click of button:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, YOUR_RESULT_CODE);

you can set a filter for third-party file browsers. Or you can try to use this file dialog: http://code.google.com/p/android-file-dialog/

Tijo Thomas
  • 166
  • 1
  • 2
  • 10
  • in MainActivity: private void showFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("file/*"); startActivityForResult(intent, -1); try { startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), -1); } catch (android.content.ActivityNotFoundException ex) { // Potentially direct the user to the Market with a Dialog Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); } } & set onClick but app crashes – Jerry00 Apr 04 '17 at 05:41
  • pleaseee help me – Jerry00 Apr 04 '17 at 05:51
  • send the crash report – Tijo Thomas Apr 04 '17 at 06:21
  • where/how can I find this? I've enabled developer options in my Nexus 5X emulator – Jerry00 Apr 04 '17 at 16:23
  • I tried having the button's onClick as showFileChooser[MainActivity] when I did this – Jerry00 Apr 04 '17 at 17:10
  • while running u have a logcat running send me the screenshot or report of the errors... – Tijo Thomas Apr 05 '17 at 04:05
  • the logcat stuff is in a photo – Jerry00 Apr 05 '17 at 22:37