|
Monday, 18 May 2009 17:41 |
|
I'm working on a BlackBerry Java application that uses the DeviceInfo class to determine information about the device the application is running on. The original version of the program I wrote used DeviceInfo.isInHolster() to determine whether the device is in the holster or not, but the documentation says that method has been deprecated. The problem is that it doesn't say what to use in its place (actually, I finally noticed the 'Deprecated' link at the top of the JavaDocs that listed the objects, methods and fields that had been deprecated but that's not the point of this story).
It turns out that the method has been implemented (of sorts) in net.rim.device.api.system.Sensor. Unfortunately, instead of returning a simple Boolean True or False, it has been implemented through a call to:
Which returns an integer value.I struggled with this because I'm just not a day to day Java developer. What I missed in the docs was that it returns an integer and the possible states are Sensor.STATE_IN_HOLSTER and Sensor.STATE_OUT_OF_HOLSTER. Here's what it said:
getState
public static int getState(int sensorId)
Return the last known state of a sensor.
Parameters:
sensorId - The ID of sensor
Returns:
the last known state of the given sensor
Throws:
IllegalArgumentException - If sensorId does not represent a supported sensor
Since:
JDE 4.6.0
Anyway, I finally figured it out this morning with some help from Sanyu from RIM. Here's an application that uses a SensorListener to determine sensor state:
package com.jwargo.SensorTest;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.SensorListener;
import net.rim.device.api.system.Sensor;
public class SensorTest extends UiApplication implements SensorListener {
public static void main(String[] args) {
SensorTest st = new SensorTest();
st.enterEventDispatcher();
}
public SensorTest() {
pushScreen(new SensorTestScreen());
Sensor.addListener(Application.getApplication(), this, Sensor.HOLSTER);
}
public void onSensorUpdate(int sensorId, int update) {
if (update == Sensor.STATE_IN_HOLSTER) {
Dialog.alert("Device is holstered");
} else {
Dialog.alert("Device is not holstered");
}
}
}
final class SensorTestScreen extends MainScreen {
public SensorTestScreen() {
super();
// Create the screen's title
LabelField lblTitle = new LabelField("Sensor Test", LabelField.ELLIPSIS
| LabelField.USE_ALL_WIDTH);
setTitle(lblTitle);
}
}
|
|
|
Saturday, 16 May 2009 20:27 |
I'm knee deep in my book on BlackBerry development (BlackBerry Development Fundamentals - www.bbdevfundamentals.com ) and I'm running into a rather annoying problem. The machine I'm doing most of my writing on is running Microsoft Vista 64-bit and while the BlackBerry device simulators run on Vista, they won't close when run on a 64-bit version of Vista. RIM is aware of the problem, but the Java development environment and the Visual Studio tools I'm working with both require that you close the simulator before you can go back in and edit the source code. Very annoying, I hope they fix that problem soon. |
|
Wednesday, 13 May 2009 12:05 |
|
Learned something interesting about the BES 5.0 upgrade. When you upgrade an existing BES domain, Administrator accounts and Roles are deleted. What this means then is that a large organization upgrading a BES 4.1.x BES to 5.0 will have to quickly re-add the Administrator accounts and roles so other Administrators will be able to continue to be able to manage the environment. |
|
Tuesday, 12 May 2009 07:04 |
|
I presented at a Domino Developer's conference in Boston a few weeks ago and provided a sample application that I used in my session. Unfortunately I forgot that in Notes 8 (might have started in Notes 7, I don't remember) local encryption is turned on by default. I got an email from a participant last week telling me he couldn't access the database so I had to create a new copy without local encryption and send it to him and to the conference. How silly. I had to contact the conference people and get them a copy. If you attended the session and have the encrypted database on the conference CD, just contact the conference people or me (using the email address in the presentation) and you'll get a new copy. |
|
Monday, 11 May 2009 08:53 |
|
Broke the screen on my BlackBerry Bold 9000 Smartphone yesterday. While switching to an 8830 I had in a drawer, I encountered a 507 error while switching from one device to another. After much trial and error, I discovered that I had to pull the battery, connect the device to the BlackBerry Desktop Manager and reload the device software. the problem was that it would get so far and give me a 507 error again. What I ultimately had to do is start the process again and put the battery in right when it finishes the software load and resets the device. You can't have a battery in to reload from scratch, but you do have to have a battery in to restart after the load. It would have been nice if Desktop Manager had warned me. That would have saved me about 30 minutes of trial and error. |
|
|
<< Start < Prev 21 22 23 24 Next > End >>
|
|
Page 24 of 24 |