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

Native Development

Reply
Developer
mmarion
Posts: 58
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers
Accepted Solution

create folders in shared or sdcard

Hey folks,

 

I'm having a problem creating folders under shared or sdcard.

 

bool ok;

QString share = QDir::currentPath() + "shared/db";

QDir tmp(share);

if(!tmp.exists()) {

    ok = tmp.mkpath(share);

}

 

ok will always be false.  I've tried taking out the currentPath and just using share/db but doesn't work.

 

NOTE: I have shared_access permissions set.

 

As far as the sdcard, I've tried:

 

QString sdcard = QDir::currentPath() + "../../removable/sdcard/db";

 

as my path and it also never works.

 

Any idea?  All I can see in the docs is that I need the shared_access permission but that's it, the implication is that it should be working for me.  There's also nothing about how to access the sdcard, I just noticed that it was ../../ back from the working folder...

 

Thanks,

 

Matt M

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: create folders in shared or sdcard

You can't create folders at that level. Please read this for more: https://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.d...


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
mmarion
Posts: 58
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: create folders in shared or sdcard

Thanks, that was good to read but what about sd card?

 

Scenario:

 

I have an app that creates a file.  I want this file to be in it's own folder.  This folder must be accessible via a PC when plugged in.

 

This has to be possible.  I can't believe there's no way to access the sdcard.  What's it's point if that's the case? 

How does one access the sd card even just to read?  It's not in any folder below the working one that I can see...

 

Thanks,

 

Matt M

Please use plain text.
Developer
mmarion
Posts: 58
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: create folders in shared or sdcard

Figured it out.

 

The link above says:

 

"Applications cannot create new directories in it's working directory; they can only access the folders listed below."

 

I was going by that...

 

QDir tmp;
ok = tmp.mkpath("/accounts/1000/removable/sdcard/misc");  // Use mkpath in case it exists as mkdir will return false
if(!ok) {
    int b = 999;
}

ok = tmp.mkpath("/accounts/1000/removable/sdcard/misc/db");  // Use mkpath in case it exists as mkdir will return false
if(!ok) {
    int b = 999;
}

QDir tmp2;
ok = tmp2.mkpath("/accounts/1000/shared/misc/db");  // Use mkpath in case it exists as mkdir will return false
if(!ok) {
    int b = 999;
}

 

That creates misc/db on the sdcard and db in the misc folder in the shared and that is what I was looking for.  While shared is below working, sdcard is not...

 

Hope this helps someone else.

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: create folders in shared or sdcard

[ Edited ]

Yeah, basically you can't create new folders at the top level of any of the shared filesystems, whether on device or sdcard. the shared filesystem on the device, though you can on the SD card.  (Edited after Innovatology corrected me.)

Note also that using absolute paths like that would mean your app can't be used in the corporate perimeter, so you'd eliminate the possibility of enterprises making it available for use other than on the personal side.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: create folders in shared or sdcard

[ Edited ]

peter9477 wrote:
Yeah, basically you can't create new folders at the top level of any of the shared filesystems, whether on device or sdcard.

Sure you can. Try it with the file manager.

 

Might it be the 64-bit file system issue?

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.
Developer
mmarion
Posts: 58
Registered: ‎05-03-2013
My Device: Z10
My Carrier: Rogers

Re: create folders in shared or sdcard

@Peter: So how does one access the sd card in an enterprise application? Just not allowed?
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: create folders in shared or sdcard


Innovatology wrote:

peter9477 wrote:
Yeah, basically you can't create new folders at the top level of any of the shared filesystems, whether on device or sdcard.

Sure you can. Try it with the file manager.


Oops! For the SD card, you're right. I suppose since it's removable and you could modify any part of it on another system (e.g. PC) they didn't bother to restrict it in the same way.

 

Serves me right for making an assumption there... I hadn't tried it before, obviously.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: create folders in shared or sdcard


mmarion wrote:
@Peter: So how does one access the sd card in an enterprise application? Just not allowed?

I forget the details, but I believe that may be the case. Or possibly it's allowed only if encrypted?  Anyway, that's a question beyond my pay grade right now. :-)

 

Anyway, my comment was more about hardcoding absolute paths, in general. For example, the corporate app area was (last time I checked) under /accounts/1000_corp instead of /accounts/1000 so an app that tried to get to its shared space via /accounts/1000/shared/misc/db would be coupled to the personal perimeter and may not work as intended in an enterprise.


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: create folders in shared or sdcard

There is a symlink /sdcard2 to the physical SD card. The symlink is always present, even if there is no SD card inserted. If no SD card is present, the directory will be empty.

 

The /sdcard symlink is for the Android runtime of course. 

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.