0

First of all i would like to tell you, i am new to blackeberry development.

Somehow i have developed an application in BB 5.0.0 and above.

I have a functionality to implement where i can download BB app (like .cod file) and upgrade it, from with in my app.

Upgraded app will be kept on my company server and when i call my sever and find upgraded version, i can upgrade it programmatically.

I referred this link and originally found references here

Not able to get this task done with above solution. I think above URL solution needs BB AppWorld as a mediator or upgraded version to be kept on BB App server.

Please let me know whether i can upgrade my BB app by downloading and replacing from within it by executing some code without keeping it on BB App world and if yes then whether i can achieve this with above referred link.

This is possible in Android and J2ME and not possible in iOS, but don't know about Blackberry.

Edit:

I implemented installer app code given in official blackberry developer site and getting following exception. Check my logs.

{"FileSize":2338776,"FileName":"MyApp_3.0.1.cod","LatestBuild":"2","LatestVersion":"3.0.1","DownloadURL":"http://myserver.link/uploads/116/MyApp_3.0.1.cod"}
 0:08:38.025: MyApp is being upgraded to version 3.0.1
 0:10:31.509: [AppWorld] - 01/23 11:38:00    INFO  Updater run() Update check at: Thu Jan 23 11:38:00 GMT 2014      
 0:10:31.511: [AppWorld] - 01/23 11:38:00    DEBUG  AbstractDatabase readDatabase()      
 0:10:31.513: [AppWorld] - 01/23 11:38:00    DEBUG  Updater run() Updater Content Installs 5      
 0:10:31.516: [AppWorld] - 01/23 11:38:00    DEBUG  Connecting to: 80bba47723dae059a32abfff7844cea89fbb7bc1e90e3ed8159e626b8427aeac825047d8b3dbc418dbf3b04b6dfd17a6f063f3d7cd6a0ed860be0c9f81cf58f488916d58a1d5b3fc52f1806693b9f8179b9fc9de5643c62f2bf92f4945716455af200982fa
 0:10:31.518: 1618056b5bddb91f830ae1d11076db1ec2adb6      
 0:10:31.519: [AppWorld] - 01/23 11:38:00    DEBUG  Connection Method: DEVICE      
 0:10:31.940: [AppWorld] - 01/23 11:38:00    INFO  AppStoreConnection: HTTP 200 , Content-Length: 2497      
 0:10:31.942: [AppWorld] - 01/23 11:38:00    INFO  Appworld server reporting minimum version: 4.0.0.55 our local version is: 2.1.4.13      
 0:10:31.944: [AppWorld] - 01/23 11:38:00  22  ERROR  An error has occur while updating.  Updater load() id1  null  
 0:10:31.948: VM:PISVt=0,h=4d1e,id=d15a33128dfbb5d9
 0:10:31.949: VM:LNTDa=commit,t=1,p=net_rim_bb_appworld_updater,h=135
 0:10:31.951: [AppWorld] - 01/23 11:38:00  22  ERROR  An error has occur while updating.    null  
 0:10:31.954: VM:PISVt=0,h=4d1e,id=d15a33128dfbb5d9
 0:10:31.956: VM:LNTDa=commit,t=1,p=net_rim_bb_appworld_updater,h=135
 0:10:31.957: [AppWorld] - 01/23 11:38:00    INFO  Updater rescheduleUpdateTime() Attempting to schedule Next Update at Thu Jan 23 12:08:00 GMT 2014      
 0:10:31.959: AM: App net_rim_bb_appworld_updater is trying to schedule for time: 1390478880504
 0:10:31.960: AM: Scheduled net_rim_bb_appworld_updater for 1390478880000
 0:10:31.962: [AppWorld] - 01/23 11:38:00    INFO  AppWorld Updater Rescheduled @ Thu Jan 23 12:08:00 GMT 2014      
 0:10:31.971: Process net_rim_bb_appworld_updater(303) cleanup started
 0:10:31.972: Process net_rim_bb_appworld_updater(303) cleanup done
 0:10:38.055: Exception: java.io.InterruptedIOException: Local connection timed out after ~ 120000 downloading URL: http://myserver.link/uploads/116/MyApp_3.0.1.cod
 0:10:38.059: FD Back On
 0:10:38.061: Exception during install of MyApp java.lang.NullPointerException
 0:10:38.064: MyApp 3.0.1 failed to upgrade.
 0:10:38.117: FocusHistory: Focus gained; App net_rim_services_impl; Component net.rim.device.api.ui.component.ButtonField

Update

Installer code i kept for my purpose in my app:

CodeModuleGroup cmGroup = new CodeModuleGroup(appInfo.getModuleGroupName());
cmGroup.setFriendlyName(appInfo.getModuleGroupFriendlyName());
cmGroup.setVersion(appInfo.getVersion());   
cmGroup.setVendor(appInfo.getVendor());

//Download and save all of the cod files.
//for(int count = 0; count < numOfCods; ++count)
//{
    byte[] codData = downloadFile(appInfo.getDescriptorURL());

//  if (codData != null)
//  {
    //Create the new cod file.
    moduleHandles = CodeModuleManager.createNewModule(codData.length, codData, codData.length);

    //Save the module
    int result = CodeModuleManager.saveNewModule(moduleHandles, true);
    log("Result code :"+result);
    //Ensure that the cod file was saved.
    if (result != CodeModuleManager.CMM_OK && result != CodeModuleManager.CMM_OK_MODULE_OVERWRITTEN)
    {
            //The cod file was not saved.
        throw new Exception("Failed to save cod."+result);
    }

    //Add the CodeModule to the CodeModuleGroup.
    cmGroup.addModule(CodeModuleManager.getModuleName(moduleHandles));  

I am getting result = 10 which is CodeModuleManager.CMM_HANDLE_INVALID, now due to this next condition throws exception and so on, now i have found out that file is actually getting downloaded but when it tries to save, int result = CodeModuleManager.saveNewModule(moduleHandles, true); at this line i am getting CMM_HANDLE_INVALID. If anyone knows the issue please let me know.

Thanks in advance.

Community
  • 1
  • 1
Ankit
  • 1,148
  • 3
  • 15
  • 31
  • Can you please supply a reference (link) to the installer code you are implementing? – Peter Strange Jan 23 '14 at 16:20
  • I am using the code given in official KB article, there is a attachment named Installer.zip, http://supportforums.blackberry.com/t5/Java-Development/Programmatically-install-and-upgrade-applications/ta-p/443008 – Ankit Jan 24 '14 at 05:59
  • Well next time please just put the log message that come from your application, or are related to your application. You did not even have to post this log - the one Exception that is relevant is all we needed. – Peter Strange Jan 24 '14 at 09:50

1 Answers1

1

You have referenced an official KB article:

Programmat​ically install and upgrade applicatio​ns

That article says the following: Note: An application cannot upgrade itself.

So in order to achieve what you want to do, you will have to create an installer application, as described in the KB article.

This means you will have to download the required files from your corporate Server in your program, and so you might have the usual network problems. I note that you reported a timeout issue as a comment in another Thread. That goes with the territory sorry, you will possibly need to spend some time getting your networking code working.

That aside, the options and information you found in your other link:

How to implement auto-update feature in blackberry

seems to me to be a pretty complete description of your options.

Update

I have waded through the log you supplied and fished out the one message that appears to be relevant:

Exception: java.io.InterruptedIOException: Local connection timed out after ~ 120000 downloading URL: http://myserver.link/uploads/116/MyApp_3.0.1.cod

So you have a network error or issue trying to retrieve that cod. This is a networking issue and not related to the installer at all. I suggest you work out why the installer is trying to reference that file and why the Server is not supplying it. If the URL is valid, then you might have to update the MIME parameters so that the Server knows that the .cod file extension should be treated as a binary file.

Further Update

You have made a changes to the code supplied, including removing support for multiple cod files for the same Application. Can I suggest you test the download code using the supplied installer and code, and when you get that working, bolt the working code into your application. Then if you have a problem, it is much easier for us to recreate it and/or test.

A suggestion

Rather than do all this, might it be better for the application to check if it is the most current, and if not, don't start up, instead start the Browser of a web page which is the OTA download of the current application. Then all you have to maintain is OTA URL - the application can check the jad to see if the version in there is the same as the current version. You have already written code that effectively does this part, you can bolt this into the application, and then you will not need an installer program. Just a thought.

Community
  • 1
  • 1
Peter Strange
  • 2,640
  • 11
  • 11
  • I am using the code given in official KB article for installer app logic, now in that code when .cod file is downloaded and on the basis of that .cod file other cods are tried to download there i am getting error. Read logs in my question. AFAIK i get only one .cod file while creating a build then what other .cod files that code needs. – Ankit Jan 23 '14 at 15:06
  • I also checked my network code, with replacing other http code, but found that my file is getting downloaded by printing its byte code, so network code is fine but it throws wrong handle error while saving the file / module using CodeModuleManager. Please suggest. – Ankit Jan 24 '14 at 12:41
  • I made installer app code working, i was directly trying to install cod file which is generated after signing in deliverables\standard\[version no], but afterwards i came to know we need to extract that .cod file and use multiple or sibling .cod files. Now looking for better option, whether i should download more than 15 cod files and update app or else as suggested by you download and update via browser using OTA URL. – Ankit Jan 30 '14 at 07:59
  • One more question, if i implement like you suggested then do i have to keep .jad and main .cod file altogether on server. As i tried solution suggested here http://stackoverflow.com/questions/5206556/how-to-implement-auto-update-feature-in-blackberry , i kept only jad file on sever and tried to download, browser showed me default page with download button, when i pressed download, it threw an error "907 Invalid cod", but i had kept only jad file on sever, in this case what files i need to upload on sever to make it working or any reference tutorial would be great. – Ankit Jan 30 '14 at 08:08
  • Hi i have implemented app update as you said as well. Kept jad and all cod files on OTA sever and did as suggested here : http://stackoverflow.com/questions/18532138/how-to-install-blackberry-app-ota – Ankit Feb 03 '14 at 13:39