To handle new app updates, the app listens for updated from the server and acts accordingly.
public void handleNotify(JSONObject json) throws JSONException{
JSONObject json_obj = json.getJSONObject("result"); //Check for update variable if(json_obj.getString("type").equals("update")){System.out.println("Update Found for..."+app_version); String[] latest_version = split(json_obj.getString("ver"), "."); String[] current_version = split(app_version, ".");
//Assign new verion number to app_version variable to avoid future //checks during current session app_version = json_obj.getString("ver"); //Compare versions and enable update download if(!latest_version[0].equals(current_version[0])){ //Force download update cmd_update = new Command("Update", Command.OK, 0); cmd_exit = new Command("Exit", Command.EXIT, 1); Alert alert = new Alert("Update", "New Update available.\nPlease Download", null, AlertType.CONFIRMATION); alert.addCommand(cmd_update); alert.addCommand(cmd_exit); alert.setCommandListener(this);
Display.getDisplay(this).setCurrent(alert);
//Sleep midlet try {
Thread.sleep(100000); //Force App close instance.notifyDestroyed(); } catch (InterruptedException ex) { ex.printStackTrace(); } }else if(!latest_version[1].equals(current_version[1])){ //Ask to update cmd_update = new Command("Update", Command.OK, 0);
Alert alert = new Alert("Update", "New Update available.\nPlease Download", null, AlertType.CONFIRMATION); alert.addCommand(cmd_update);
alert.setCommandListener(this);
Display.getDisplay(this).setCurrent(alert);
//Sleep midlet try { for(int i=10; i>0; i--){
alert.setString("["+Integer.toString(i) +"] "+"New Update available.\nPlease Download"); Thread.sleep(1000); }
} catch (InterruptedException ex) { ex.printStackTrace(); } }else if(!latest_version[2].equals(current_version[2])){ //Ask to update cmd_update = new Command("Update", Command.OK, 0);
Alert alert = new Alert("Update", "New Update available.\nPlease Download", null, AlertType.CONFIRMATION);
alert.addCommand(cmd_update);
alert.setCommandListener(this);
Display.getDisplay(this).setCurrent(alert);
//Sleep midlet try { for(int i=10; i>0; i--){
alert.setString("["+Integer.toString(i) +"] "+"New Update available.\nPlease Download"); Thread.sleep(1000); }
} catch (InterruptedException ex) { ex.printStackTrace(); } }
}
}//--End of handleNotify(JSONObject);
//Ask to update
cmd_update = new Command("Update", Command.OK, 0);
cmd_exit = new Command("Exit", Command.EXIT, 1);
Alert alert = new Alert("Update", "New Update available.\nPlease Download", null, AlertType.CONFIRMATION);
alert.addCommand(cmd_update);
alert.addCommand(cmd_exit);
alert.setCommandListener(this);
Display.getDisplay(this).setCurrent(alert);
No comments:
Post a Comment