• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

how to open directory on android

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi i am trying to open a directory and get file uri after selecting a file but am getting null pointer





but am getting error

 
Saloon Keeper
Posts: 28242
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A word of caution.

Android isn't really designed to work with files. Persistent data is commonly kept in (MySQL) databases.

Android itself runs under Linux, so what you would be doing is effectively dropping from Android into the Linux OS. Significantly, Android doesn't run as a privileged user in its host OS, so in many cases Android apps cannot access files/directories as they are owned by a different userID.
 
Master Rancher
Posts: 5026
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you see this:
https://stackoverflow.com/questions/53748248/java-lang-nullpointerexception-attempt-to-invoke-virtual-method-android-app-ac
 
john bean
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for replys what i am trying to do is navagate through phone and select a file for mediaplayer and save the link in my app sorry have not replied sonner windows broke my debian I HATE WINDOWS!
 
Tim Holloway
Saloon Keeper
Posts: 28242
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm. I mostly just launch Mediaplayer straight from the File Manager app actually. I think VLC can create playlists on Android devices, and you can use File Manager to create a media "save list" directory as well.

The File Manager is kind of quirky, as it has to deal with both built-in (permanent) storage and swappable (SD card) storage, so that's also a consideration.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think an approach like https://developer.android.com/training/data-storage/shared/documents-files#open-file is more in tune with current Android practices.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, "External" is "external to the app". On newer versions of Android you need whole new practices for that: Try to read about content manager and saving docs.
That content manager has an internal database under the hood, and you have to let Android manage those files for you.
Avoid storing files in a fixed position. Android won't let you, since 12 - if I remember correctly. The global storage party is over :-(
If you need to share files, consider storing them in your app area (maybe Cache if you don't care much about them after sharing), and use **content providers** (a mechanism that allows apps to share pieces of data to the outside via some URL. It's a little boilerplate... well).
If you must use external storage, be aware that Android requires lots of frightening permissions (some kind of "full storage access").

Now, note that this maps basically to /sdcard/Files. Does this directory exist?
Don't use getenv("EXTERNAL_STORAGE") + "/Files"
Use File(Environment.EXTERNAL_STORAGE_something, "Files").
That's because you want to see where it puts you. With the debugger, when you inspect a File() object, you can view the absolute path (usually also with toString()), and check if isFile() or isDir() or exists().

Oh, and ... Tim Holloway: NOT MySQL! It's always SQLite! < Covering the eyes of children here :-D >
 
Tim Holloway
Saloon Keeper
Posts: 28242
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeeks! I said MySQL??? What was I thinking???

SQLite it is.
 
john bean
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for replys have hit have been afk for a few week "f ing work!" but have hit an unusual problem ... my phone samsung a14g5 did a software update and now im getting runtime error
 E  FATAL EXCEPTION: main
                                                                         

this seems to be a prob at samsung os level my eq works on emulator but when run on phone it crashes at launch but i have tried a few different eqs and they work does anyone know a fix?

the code throwing error is


thanks for any help
 
Marshal
Posts: 28306
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code you posted simply takes the integer value it's given and throws a suitable exception which corresponds to that value. So some other code has had a problem and called that method to throw an exception.

In other words, the posted code tells us nothing about the problem, except what the words in the exception say. The stack trace tells us that the method "android.media.audiofx.Equalizer.usePreset" had that problem.
 
john bean
Ranch Hand
Posts: 106
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k just an update when running i got error i uninstalled on device then tried and it worked sry should have tried that
 
Paul Clapham
Marshal
Posts: 28306
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I always forget the "uninstall and reinstall" method for fixing Android apps too. Anyway, thanks for letting us know!
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I always forget the "uninstall and reinstall" method for fixing Android apps too.


It's really disappointing that this Windows approach to troubleshooting also applies to a Linux OS like Android.
 
Tim Holloway
Saloon Keeper
Posts: 28242
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Windows locks files based on their names, so a lot of system updates can only be done when no process has locked files affected by the update. Essentially, for a short period in the Windows Boot process, Windows is running invisibly in "DOS" mode where you don't have all those processes locking the files. Unix/Linux are not so constrained because they lock on inodes, and the connection between filename and inode can be re-mapped to another inode at almost any time, with existing holders of the old node retaining it until they release it. A side effect of that being that you can delete an open file, but the space it uses won't be freed until after the file is closed.

Android apps, on the other hand are more like a bundle of running classes and replacing running code on the fly is trickier than re-pointing to a different file, since you have to evict the old code from the classloader.

Actually Java had a really bad problem for certain Tomcat releases because back then Java supported a special memory partition called "PermGen" space. Certain static objects would get stored in PermGen and couldn't be replaced without restarting the JVM. which meant that even though Tomcat supported (and still supports) hot updates on apps, their PermGen components would remain and eventually you'd be forced to restart when the PermGen space ran out.
 
Paul Clapham
Marshal
Posts: 28306
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

I always forget the "uninstall and reinstall" method for fixing Android apps too.


It's really disappointing that this Windows approach to troubleshooting also applies to a Linux OS like Android.


Indeed it is. But it's worked for me twice. (Both times on obscure apps which weren't highly rated.)

I'd blame the apps rather than the OS, although it's hard (for me) to see why an app should one day start declaring that it can't play any WAV files, that being one of its standard features.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic