1. Make Model Class with Persistable interface Implementaion
public class User implements Persistable {
String userName;
String password;
String casinoCode;
boolean saveUserInfo;
public boolean isSaveUserInfo() {
return saveUserInfo;
}
public void setSaveUserInfo(boolean saveUserInfo) {
this.saveUserInfo = saveUserInfo;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCasinoCode() {
return casinoCode;
}
public void setCasinoCode(String casinoCode) {
this.casinoCode = casinoCode;
}
}
2. Store object with Persistent API on Load
PersistentObject _store = PersistentStore.getPersistentObject(PERSISTENT_STORE_ID);
synchronized(_store)
{
try {
if(_store.getContents() == null)
{
User user= new User();
user.setCasinoCode("");
user.setPassword("");
user.setUserName("");
user.setSaveUserInfo(false);
_store.setContents(user);
_store.commit();
}
} catch (Exception e) {
PhotoAPP.errorDialog(e.toString());
}
}
3. Save Data with Peristent API
public static void persist(User user)
{
_store = PersistentStore.getPersistentObject(PERSISTENT_STORE_ID);
synchronized( _store )
{
_store.setContents(user);
PersistentObject.commit(_store);
}
}
4. Retrieve data with Persistent API
public static User getPersistentObject() {
_store = PersistentStore.getPersistentObject(PERSISTENT_STORE_ID);
User user = (User)_store.getContents();
return user;
}
Monday, April 11, 2011
File Upload With Blackberry
String url ="http://www.sitename.com/upload_bb_photos.php";
url= url+"?arg1=arg1";
if (DeviceInfo.isSimulator()) {
url = url + ";deviceSide=true";
}else{
// url = url + ";interface=wifi";
}
HttpConnection http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("User-Agent", "APP_NAME");
FileConnection fconnFrom = null;
int fileSize = 0;
fconnFrom = (FileConnection) Connector.open("pic_full_path");
if (fconnFrom.exists()) {
fileSize = (int) fconnFrom.fileSize();
http.setRequestProperty("Content-Length",
String.valueOf(fileSize));
}
OutputStream oStrm = http.openOutputStream();
byte imgData[] = new byte[fileSize];
DataInputStream dataIn = fconnFrom.openDataInputStream();
dataIn.read(imgData, 0, fileSize);
int index = 0;
int size = 1024;
do {
if ((index + size) > imgData.length) {
size = imgData.length - index;
}
oStrm.write(imgData, index, size);
oStrm.flush();
index += size;
} while (index < imgData.length);
url= url+"?arg1=arg1";
if (DeviceInfo.isSimulator()) {
url = url + ";deviceSide=true";
}else{
// url = url + ";interface=wifi";
}
HttpConnection http = (HttpConnection) Connector.open(url);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("User-Agent", "APP_NAME");
FileConnection fconnFrom = null;
int fileSize = 0;
fconnFrom = (FileConnection) Connector.open("pic_full_path");
if (fconnFrom.exists()) {
fileSize = (int) fconnFrom.fileSize();
http.setRequestProperty("Content-Length",
String.valueOf(fileSize));
}
OutputStream oStrm = http.openOutputStream();
byte imgData[] = new byte[fileSize];
DataInputStream dataIn = fconnFrom.openDataInputStream();
dataIn.read(imgData, 0, fileSize);
int index = 0;
int size = 1024;
do {
if ((index + size) > imgData.length) {
size = imgData.length - index;
}
oStrm.write(imgData, index, size);
oStrm.flush();
index += size;
} while (index < imgData.length);
Center Align of Element HorizontalManager
HorizontalFieldManager hf = new HorizontalFieldManager(Field.FIELD_HCENTER);
ButtonField backButtonField= new ButtonField("Back", Field.FIELD_HCENTER );
hf.add(backButtonField);
ButtonField backButtonField= new ButtonField("Back", Field.FIELD_HCENTER );
hf.add(backButtonField);
Monday, March 21, 2011
internet connection with blackberry code
Internet Connection With Blackberry Java
String url= "http://www.test.com/test.jsp"
HttpConnection hc = (HttpConnection) Connector.open(url);
hc.setRequestMethod(HttpConnection.GET);
InputStream inputStream = hc.openInputStream();
if (DeviceInfo.isSimulator()) {
url = url + ";deviceSide=true";
}
String result = "";
for (int ch = inputStream.read(); ch != -1; ch = inputStream.read()) {
result = result + (char) ch;
}
String url= "http://www.test.com/test.jsp"
HttpConnection hc = (HttpConnection) Connector.open(url);
hc.setRequestMethod(HttpConnection.GET);
InputStream inputStream = hc.openInputStream();
if (DeviceInfo.isSimulator()) {
url = url + ";deviceSide=true";
}
String result = "";
for (int ch = inputStream.read(); ch != -1; ch = inputStream.read()) {
result = result + (char) ch;
}
Thursday, March 17, 2011
Tuesday, March 15, 2011
Subscribe to:
Comments (Atom)