If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
New Developer
satyam
Posts: 7
Registered: ‎07-18-2008
My Device: Not Specified
Accepted Solution

Uninstalling application programatically

Hi ,

is there any API available using which we can uninstall our application from device .

also can we upgrade our application running in background without user intervention?

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uninstalling application programatically

Here is some code I use in a menu to remove an application.  Hope you find it useful.  In fact I've removed this menu item from the application, because it always required the device to be restarted, which meant it was actually easier for the user to delete via the Options-->Advanced Options-->Applications screen, because that automatically restarts the device.  [I've yet to find a way to programatically restart the device]

 

private MenuItem _deleteeMenu = new MenuItem("Delete Tool", 110, 10) { // Delete us public void run() { int actionCode = Dialog.ask("Confirm Deletion", new String [] { "Continue", "Cancel" }, new int [] { 0, 1 }, 0); if ( actionCode == 0 ) { ApplicationDescriptor ad = ApplicationDescriptor.currentApplicationDescriptor(); int moduleHandle = ad.getModuleHandle(); int rc = CodeModuleManager.deleteModuleEx(moduleHandle, true); String tellUserMessage = ""; if ( rc == CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION ) { tellUserMessage = "Please restart the device to remove the application"; } else if ( rc == CodeModuleManager.CMM_OK ) { tellUserMessage = "Deleted"; } else { String errorString = Integer.toString(rc); switch (rc) { case CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION: tellUserMessage = "Will be deleted on restart"; break; case CodeModuleManager.CMM_MODULE_IN_USE: case CodeModuleManager.CMM_MODULE_IN_USE_BY_PERSISTENT_STORE: tellUserMessage = "Module In Use"; break; case CodeModuleManager.CMM_HANDLE_INVALID: tellUserMessage = "Invalid Handle"; break; case CodeModuleManager.CMM_MODULE_REQUIRED: tellUserMessage = "Module Required"; break; default: tellUserMessage = Integer.toString(rc); break; } tellUserMessage = "Error Deleting Module: " + tellUserMessage; } Dialog.alert(tellUserMessage); } } };

 

Regarding updating your application, the first trick is actually determining there is an upgrade available.  There are various options for this, I'll assume you choose one based on your requirements.

 

Once you know there is an upgrade, you could push the user into the Browser with the download page open, rather than trying to do it yourself. 

 

if you want to do it yourself, CodeModuleManager seems to have the APIs that you would need, though you may not be able to install it (especially over the top of an existing version), without a restart.

Please use plain text.
BlackBerry Development Advisor (Retired)
ttahir
Posts: 36
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uninstalling application programatically

Just to add to that, you can use CodeModuleManager.promptForResetIfRequired() to prompt the user to reboot. Invoking this method will have no effect if there a reset isn't required. We added this method in JDE v4.2.0.

 

Tariq

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uninstalling application programatically

Thanks for that Tariq, hadn't spotted that method being introduced in 4.2.
Please use plain text.
New Developer
satyam
Posts: 7
Registered: ‎07-18-2008
My Device: Not Specified

Re: Uninstalling application programatically

thanx a lot peter and tariq ..

that is really helpful

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Uninstalling application programatically

if ( rc == CodeModuleManager.CMM_OK_MODULE_MARKED_FOR_DELETION ) { CodeModuleManager.promptForResetIfRequired(); tellUserMessage = "Please restart the device to remove the application"; } else

 

To use the promptForResetIfRequired() method, I've changed the code as above (I'm sure you can see where it goes).  With this in place, the menu item has been reinstated.

 

 

Please use plain text.
Developer
sunil_garlapati
Posts: 69
Registered: ‎08-25-2008
My Device: Not Specified

Re: Uninstalling application programatically

I have used same code for unistalling the application. Is there any other api to uninstall the application without reset the device.  In BBDevice  i can uninstalling application without restarting the device through the 'options' menu item.  But with this code snippet, user gets prompted to restart the device if the uninstall option is chosen from the context menu. Why is this and is it really required?

 

Advanced thanks for any reply.

Please use plain text.
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Uninstalling application programatically

Please see the link below.  The same reasons also apply to deleting an application.

 

What Is - The reason a reset is required when upgrading an application
Article Number: DB-00602

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.