Monday, December 5, 2011

How to find the RMS Storage space using J2ME


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import java.io.*;
import java.lang.*;
/**
* @author test
*/
public class rms extends MIDlet implements CommandListener {
      private RecordStore rs=null;
      private Form form;
      private Display display;
      private StringItem si1,si2,si3;
      private Command exit;
      public void startApp() {
            display=Display.getDisplay(this);
            form=new Form("RMS Storage Space");
            exit=new Command("Exit",Command.EXIT,0);
            si1=new StringItem("Phone             Memory",Runtime.getRuntime().totalMemory()+"");
            si2=new StringItem("Free Memory(Phone)",Runtime.getRuntime().freeMemory()+"");
            try {
                  rs=RecordStore.openRecordStore("Space",true);
            }
            catch(Exception e) {
            }
            try {
                  si3=new StringItem("Free Memory(RMS)",rs.getSizeAvailable()+"");
            }
            catch(Exception e) {
            }
            form.append(si1);
            form.append(si2);
            form.append(si3);
            form.addCommand(exit);
            display.setCurrent(form);
            form.setCommandListener(this);
      }
      public void pauseApp() {
      }

      public void destroyApp(boolean unconditional) {
            notifyDestroyed();
      }
      public void commandAction(Command cmd,Displayable disp) {
            if(cmd==exit) {
                  destroyApp(false);
            }
      }
}

No comments:

Post a Comment