Hai friends,

Is it possible to do auto update in j2me. For example, when the user run the application, it connects to server to see if there is new version available. If yes, than first step is to inform the user with popup or alarm. The first step is not a problem. The second step is if the user click "update", for ex, than the midlet automatically download and run the new version? is it possible to do the second step automatically or the user have to go to the website and dload the new version manually ? Have you seen in practice any midlet that is able to do auto update like this ?

Dani AI

Generated

A practical clarification and a compact, repeatable workflow.

In standard MIDP/J2ME a running MIDlet cannot silently replace its own installed suite; installation/replacement is handled by the device installer and normally requires user confirmation. The portable, reliable pattern is: the MIDlet fetches the remote JAD, compares the remote MIDlet-Version to its own, prompts the user when an update exists, and then hands the JAD/JAR URL to the device installer (typically via platformRequest). Vendor‑specific APIs or device management (OMA DM, carrier provisioning, or some BlackBerry APIs) can provide tighter automation, but those are not portable across all J2ME phones.

Typical server + client workflow (what the thread is missing)

  • Server: publish an updated JAD (include MIDlet-Version, MIDlet-Jar-URL, MIDlet-Jar-Size) and serve the JAD/JAR with correct MIME types (text/vnd.sun.j2me.app-descriptor for .jad, application/java-archive for .jar). Keep MIDlet-Jar-Size accurate.
  • Client: fetch and parse the JAD, compare versions, show a confirmation alert if the remote version is newer, then hand the installer the JAD URL. Check platformRequest's boolean return: if it returns true the MIDlet must exit (call notifyDestroyed()), otherwise the device will continue without exit.

Example (J2ME-style) helper snippets for fetching/parsing and comparing versions:

String fetchJadText(String jadUrl) throws IOException {
    HttpConnection c = (HttpConnection) Connector.open(jadUrl);
    InputStream is = c.openInputStream();
    StringBuffer sb = new StringBuffer();
    int ch;
    while ((ch = is.read()) != -1) { sb.append((char)ch); }
    is.close(); c.close();
    return sb.toString();
}

String extractAttr(String jadText, String name) {
    StringTokenizer st = new StringTokenizer(jadText, "\r\n");
    while (st.hasMoreTokens()) {
        String line = st.nextToken();
        int ix = line.indexOf(':');
        if (ix > 0 && line.substring(0, ix).trim().equalsIgnoreCase(name))
            return line.substring(ix+1).trim();
    }
    return null;
}

Practical pitfalls and tips

  • Many phones cache JAD/JAR; bump file names or add a version query to avoid stale responses.
  • If the JAR is large, some handsets or carriers will block OTA installs.
  • Some operations (file system, push, silent installs) require signed MIDlets or operator/OEM privileges.
  • A MIDlet cannot reliably delete its own old JAR; replacement/uninstall is the device/app-manager responsibility.

Relation to thread posts: pointed to platformRequest (the right general tool), but the code posted omitted checking the platformRequest return and lacked context; was correct that behavior varies by device. The approach above explains the portable method and the common platform-specific caveats.

Recommended Answers

All 4 Replies

Never seen or heard anyone to mention such option. As far I'm concerned user has to do manual update.

it's possible after showing the alert that new updated jar is available u can write this code so that it'll download that jar automatically.

try {					
	sv.platformRequest(DataMembers.updateURL);
} catch (Exception e) {
				}
sv.notifyDestroyed();

can any one tell after auto updation of that jar how to delete the old jar.

1. You just reopened 2 years old thread
2. You provided code that doesn't make any sense (what the hell is "sv" and is "DataMemebers" for)
3. You unlikely to do that with plain J2ME, maybe BlackBerry has more functionality due to it wide usage, but then it will only for BlackBerry platform and not other J2ME platforms

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.