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

Java Development

Reply
Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none
Accepted Solution

Deleting Documents after Invocation is finished.

Hi again!

 

I need to show all kinds of Documents, since It would takes years to develop a complete office suite, I figured it would be great to do just the same thing I am doing on Android and just rely on existing apps to handle this issue. Unfortunately I have to create the file on the SDCard, because Connector.open("file:///Store/home/user/") always throws a filesystem error 1003, and I my first choice which would have been invocation.setData(someContentToDisplay) and invocation.setType(someMimeType) will open DocsToGo, which will in turn tell me that the file could not be found.

Now, all of that isn't so bad, if I could just delete the file thats been written to the SDCard immediately after DocsToGo is closed, or looses focus, or even better, after DocsToGo loaded the file into RAM.

 

My current Implementation looks like this, the funny thing is that there is no exception thrown, neither is the file deleted:


DocumentEntity doc = DatabaseHandler.getInstance().getDecisionDocument(docId);
String path = "file:///SDCard/mobdec/";
FileConnection fc = (FileConnection) Connector.open(path, Connector.READ_WRITE);
if (!fc.exists()) {
fc.mkdir();
}
fc.close();
String filename = path + doc.getTitle();
fc = (FileConnection) Connector.open(filename, Connector.READ_WRITE);
if (!fc.exists()) {
fc.create();
}
DataOutputStream dos = fc.openDataOutputStream();
dos.write(doc.getContent());
dos.flush();
dos.close();

//Create the invocation request.
Invocation invocation = new Invocation(filename);
invocation.setAction(ContentHandler.ACTION_OPEN);
invocation.setResponseRequired(false);
//Use the registry to perform the invocation.
Registry registry = Registry.getRegistry("net.mobiledecision.client.blackberry.MobileDecisionScreen");
registry.invoke(invocation);

while (invocation.getStatus() != Invocation.OK && invocation.getStatus() != Invocation.ERROR && invocation.getStatus() != Invocation.CANCELLED) {
synchronized (this) {
wait(50);
}
}

fc.delete();
fc.close();

Thanks!

Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none

Re: Deleting Documents after Invocation is finished.

Sry, I forgot to mention that I am developing on BB6.

 

And is there a .method() somewhere that returns the users home directory? I mean, "file:///Store/home/user/" just CAN'T be right...

Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Deleting Documents after Invocation is finished.

There is not a concept of a 'home' directory in BBOS.

 

Regarding your problem, you are not going to like the options I will suggest:

 

a) Have a Thread that looks for active applications.  If DocsToGo is not active, then you can delete the file

b) Use a FileSystemJournalListener an dmonitor activity against your file.  When it is closed, delete it. 

 

Sorry, I can't think of anything better. 

Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none

Re: Deleting Documents after Invocation is finished.

Well, b sounds like it would be apropriate since I dont want to limit myself to DocsToGo, because I havent got any Idea what customers will use for viewing documents.

 

Thanks!

Regular Contributor
mja1986
Posts: 53
Registered: ‎08-27-2013
My Device: none

Re: Deleting Documents after Invocation is finished.

As it goes, there doesnt seem to be an event in the FileSystemJournalEntry that tells me the file got closed, so I will need to go with a and get myself a list of contenthandlers that need to be watched from the registry.