09-23-2010 05:13 PM - edited 09-23-2010 05:45 PM
I am trying to install a large MIDP app. The size of the cod is 382976. I am installing it with siblings. I have tried 2 approaches
1. Start with creating an "empty" cod
int handle = CodeModuleManager.createNewModule(totalsize);
and
int handle = CodeModuleManager.createNewModule(382976);
both approaches returns a zero handle
int handle = CodeModuleManager.createNewModule(3000);
returns a nonzero handle
I also tried to creat the first sibling segment at the first call
int handle = CodeModuleManager.createNewModule(totalsize, codInfo[0].getCodfile(), codInfo[0].getCodsize());
it gives a zero handle too.
I am running on the simulator. The large app installs ok when using other methods
Edited:
Code works for a small app
Solved! Go to Solution.
09-23-2010 06:10 PM
What the.....???
searching the web I found this:
http://www.thinkingblackberry.com/archives/141
Indicating that the API documentation is all wrong!
2 days in the drain!!!
09-23-2010 08:19 PM
There is something in the doc that talks about this 'problem' isn't there: Here it is...
How to add sibling .cod files.
You need to write the data in two separate chunks. The first data chunk must be less than 64KB in size.
1.To write the first data chunk, invoke CodeModuleManager.createNewModule( int totalLength, byte[] data, int length ).
2.To write the second data chunk, invoke CodeModuleManager.writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).
Problaby just me, but I would not have expected to write the entire cod in one hit....
09-24-2010 03:30 AM
The method for writing a cod module in separate "chunks" described in th api documentation just does not work.
2 methods are indicated. Both indicates that you keep track of the offset where to add the "chunks"
To write the first data chunk, invoke CodeModuleManager.createNewModule( int totalLength, byte[] data, int length ).
To write the second data chunk, invoke CodeModuleManager.writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).
I can not understand "totalLength" in any other way than the length of the "total" cod
The other way is a slight variation and starts with just specifying size and no data.
Create a module without data
Invoke createNewModule() and provide the size of the module in bytes as a parameter.
int handle = CodeModuleManager.createNewModule( 3000 );
Here I read "the size of the module" as the size of the complete cod module.
They both fail if the "total size" is large giving a handle = 0;
What works is the way it is described in the sample
http://supportforums.blackberry.com/t5/Java-Develo
That is a completely different way than is described in the API, You do not need to keep track of offset where to place the "chunks" and you do not need to porvide any information about "total length"
The description in the API is just plain wrong and does not work and the same documentation is in API for 6.
http://www.thinkingblackberry.com/archives/141
points this out
This is unacceptable. cost me lots of time and aggravation
The API documentatuion should be updated
09-24-2010 04:35 AM - edited 09-24-2010 04:36 AM
Having reviewed it again, I agree the documentation is wrong.
There is a "Submit Feedback" button in the OS 5.0 documentation. Use it and suggest a correction.
And thanks for bringing this to our attention on this forum so that other people having this problem can search and find the solution here.
09-24-2010 05:03 AM
OK
:-)
How do we flag this thread. Solved?
09-24-2010 06:12 AM
I think your previous post, which points out the issues and points people to the 'thinking' article, is a good solution?
09-24-2010 06:39 AM
Click 'Mark as solution' , It should be somewhere near that reply.
Cheers,
05-24-2011 06:17 AM
I am not able to access this page, http://www.thinkingblackberry.com/archives/141
Any suggestion? If anyone has this article saved, please send it to me.
Thanks
05-24-2011 07:02 AM
Not sure what has happened, but here is the content, not as well formated.
Loading sibling cods using CodeModuleManager
I recently had occasion to use the CodeModuleManager to load a module onto the BlackBerry after downloading it from a remote server. This was a bit tricky because the javadocs from RIM about CodeModuleManager are at best misleading.
The Javadocs (from 4.7) say:
How to add sibling .cod files.
You need to write the data in two seperate chunks. The first data chunk must be less thank 64KB in size.
1. To write the first data chunk, invoke createNewModule( int totalLength, byte[] data, int length ).
2. To write the second data chunk, invoke writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).
First of all, the writeNewModule method metioned is deprecated! But that’s not the worst problem - I’ll explain.
If we have an application with 3 sibling cods, with a total size of say 150000 bytes, you might think (as I did) that the above docs imply that you need to do something like this:
private void writeModule(byte[] cod1, byte[] cod2, byte[] cod3) {
int handle = CodeModuleManager.createNewModule(150000, cod1, cod1.length);
boolean result = CodeModuleManager.writeNewModule(handle, cod1.length, cod2, 0, cod2.length);
result = CodeModuleManager.writeNewModule(handle, cod1.length + cod2.length, cod3, 0, cod3.length);
CodeModuleManager.saveNewModule(handle);
}
You would be wrong! The actual way to do it is:
private void writeModule(byte[] cod1, byte[] cod2, byte[] cod3) {
int handle1 = CodeModuleManager.createNewModule(cod1.length, cod1, cod1.length);
CodeModuleManager.saveNewModule(handle1);
int handle2 = CodeModuleManager.createNewModule(cod2.length, cod2, cod2.length);
CodeModuleManager.saveNewModule(handle2);
int handle3 = CodeModuleManager.createNewModule(cod3.length, cod3, cod3.length);
CodeModuleManager.saveNewModule(handle3);
}
The BlackBerry OS knows enough to put the sibling cods together into the same module.
So the above Javadocs are wrong - you only need to write the data in two separate chunks, for an individual sibling cod file, if that cod file is bigger than 64kb. So actually the above code sample will work only if your sibling cods are each less than 64kb. If one of them is more you’ll need to do this:
int handle1 = CodeModuleManager.createNewModule(cod1.length, cod1, 64000);
CodeModuleManager.writeNewModule(handle1, 64000, cod1, 64000, cod1.length-64000);
CodeModuleManager.saveNewModule(handle1);
Of course, only if cod1.length > 64k (I just used 64000 here to be on the safe side - you could actually use 65536 (or maybe 65535?)
Share and Enjoy