Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Runtime Development

Reply
Contributor
Posts: 28
Registered: ‎11-11-2013
My Device: -
My Carrier: -
Accepted Solution

File.exists() returns false for standard Music folder

[ Edited ]

This appears really weird. For both symlink and canonical paths File.exists() returns false!

 

The following code was tested with Q10 emulator:

   

File musicFolder = 
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_MUSIC); System.out.println(
"Path \"" + musicFolder.getPath() + "\" " + (musicFolder.exists()
? "exists " : "does not exist")); try { musicFolder = musicFolder.getCanonicalFile(); System.out.println(
"Path \"" + musicFolder.getPath() + "\" " + (musicFolder.exists()
? "exists " : "does not exist")); } catch (IOException ex) { // Should not be here }

 

Output:

Path "/mnt/sdcard/Music" does not exist
Path "/accounts/1000/shared/music" does not exist

 

A propos,  the folder exists and even has some music files in it, which are played OK.

 

 

Any comments?

 

Highlighted
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: File.exists() returns false for standard Music folder

Yea ... in order to access anything under /sdcard, you need the 1000_shared gid.  Which you only get on our platform if you have the WRITE_EXTERNAL_STORAGE android permission.

 

On stock Android, you're granted READ_EXTERNAL_STORAGE permission implicitly (at least for now).  On ours you don't.

 

So, does your app have WRITE_EXTERNAL_STORAGE?  If not, try that.

Contributor
Posts: 28
Registered: ‎11-11-2013
My Device: -
My Carrier: -

Re: File.exists() returns false for standard Music folder

Thanks a lot, it really helped.

 

It is really strange that I need WRITE_EXTERNAL_STORAGE when I don't really write to it.

 

Now I need to alter Manifest all the time, using READ_EXTERNAL_STORAGE for Android Kit-Kat compatibility and WRITE_EXTERNAL_STORAGE for Blackberry, otherwise the app will frighten Android users Smiley Happy

 

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: File.exists() returns false for standard Music folder

READ_EXTERNAL_STORAGE is granted implicitly in stock JellyBean 4.2.2.  That's (somewhat) even more concerning. 

 

Perhaps it could be clearer that READ_EXTERNAL_STORAGE isn't granted implicitly on our platform, and that you need WRITE_EXTERNAL_STORAGE to grant it.  I suppose though it's better than us granting WRITE_EXTERNAL_STORAGE implcitly.

Contributor
Posts: 28
Registered: ‎11-11-2013
My Device: -
My Carrier: -

Re: File.exists() returns false for standard Music folder

[ Edited ]

I hope, for forthcoming Blackberry releases (with Android 4.4+ support)  we will need only READ_EXTERNAL_STORAGE to read  files from SD card.