Day: 18 March 2010

Auto-update of Midlets

Any professional application should be capable of updating itself over the internet. Even Midlets! The idea is fairly easy in that the Midlet needs to make a call to the server to check what version the latest software has, and compare that to the installed version. If there is a newer version available, then it needs to start the (mobile) device's browser and point it at the URL of the new JAD file. The device will take care of the download and installation after that. So, the following article shows you exactly how this can be implemented. First off, refer to the previous article, which described a framework for making server calls. The sequence diagram looks like this: Based on the framework, the following JSP can be installed serverside, which reads the version number out of the JAD file: <%@page import="java.io.FileInputStream"%> <%@page import="java.io.RandomAccessFile"%> <%@page import="java.io.File"%> <%@page import="java.util.List"%> <html> <body> <% RandomAccessFile raf = null; try{ String version = null; String path = request.getSession().getServletContext().getRealPath("index.jsp"); File f = new File(path); f = f.getParentFile(); f = new File(f, "jads/nameOfJad.jad"); raf = new RandomAccessFile(f, "r"); String curr = null; while((curr = raf.readLine()) != null){ if(curr.startsWith("MIDlet-Version:")){ version = curr.substring(16); break; } } %>OK <%=version%>| add other master data like the users details, their roles, etc. here... <% }catch(Exception e){ log.warn("failed to read master data", e); %>ERROR <%=e.getMessage() %> <% }finally{ if(raf != null) raf.close(); } %> </body> </html> This JSP is called when the Midlet starts, and effectively delivers "master data" to the device, such…

Read more