The Storage module saves the ID of the user's own business card. It consists of one class, which provides methods for abstracting access to the MIDP 2.0 Record Management System (RMS).
To implement the Storage module:
Create the Storage.java
class file.
Import the required classes.
import javax.microedition.rms.RecordEnumeration; import javax.microedition.rms.RecordStore;
Obtain the UID of the contact entry from the address book.
/** * * This class abstracts an RMS system for storing the uid of the * contact entry from the address book, selected by user as own entry. * */ public class Storage { /** * Gets the stored uid * * @return string containing uid of the the contact entry from the * address book, selected by user as own entry or null if no * contact is previously selected * @exception Exception - * in case of errors occur */ static public String getBCUID() throws Exception { String uid = null; RecordStore db = RecordStore.openRecordStore("uid", true); RecordEnumeration e = db.enumerateRecords(null, null, false); if (!e.hasNextElement()) { uid = null; } else { byte[] record = e.nextRecord(); if (record == null) { uid = null; } else { uid = new String(record); } } db.closeRecordStore(); return uid; }
Store the selected UID.
/** * Stores the uid * * @param uid - * string containing uid of the the contact entry from the * address book, selected by user as own entry * @exception Exception - * in case of errors occur */ static public void setBCUID(String uid) throws Exception { RecordStore db = RecordStore.openRecordStore("uid", true); // delete all records if (db.getNumRecords() != 0) { db.closeRecordStore(); RecordStore.deleteRecordStore("uid"); db = RecordStore.openRecordStore("uid", true); } byte[] record = uid.getBytes(); db.addRecord(record, 0, record.length); db.closeRecordStore(); } }