Ok. I've found how to find missed calls by using PhoneLogs, and to make sounds/vibrations by using a rim demo code.
I need to figure out how to let the program run in background and react to changes to phonelogs.
Questions:
1.How do I implement a Listener (specifically PhoneLogListener)? My listener does not appear to be receiving events even though I registered by listener.
2.How does one make sounds/vibractions without user directly opening my program?
code so far:
Code:
/*
* LogReader.java
* GPL'ed
*/
package freebbalerts;
import net.rim.blackberry.api.phone.phonelogs.*;
import java.lang.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
public class LogReader extends UiApplication implements PhoneLogListener{
private PhoneLogs _logs;
private String _missedCalls;
static public void main(String[] args) {
LogReader app = new LogReader();
app.enterEventDispatcher();
PhoneLogs.addListener(app);
}
private LogReader() {
_logs = PhoneLogs.getInstance();
_missedCalls = findMissedCalls(PhoneLogs.FOLDER_MISSED_CALLS);
pushScreen(new LogReaderScreen(_missedCalls));
}
public String findMissedCalls(long folder) {
int totalCalls = this._logs.numberOfCalls(folder);
int missedCalls = 0;
for(int i=0;i<totalCalls;i++){
PhoneCallLog cl = (PhoneCallLog) _logs.callAt(i,folder);
if(cl.getType() == PhoneCallLog.TYPE_MISSED_CALL_UNOPENED){
missedCalls++;
}
}
return Integer.toString(missedCalls);
}
public void callLogAdded(CallLog cl){
System.out.println("added");
ConsequenceDemo cDemo = new ConsequenceDemo();
cDemo.startN();
_logs = PhoneLogs.getInstance();
_missedCalls = findMissedCalls(PhoneLogs.FOLDER_MISSED_CALLS);
pushScreen(new LogReaderScreen(_missedCalls));
}
public void callLogRemoved(CallLog cl){
System.out.println("removed");
}
public void callLogUpdated(CallLog cl, CallLog Oldcl){
System.out.println("updated");
}
public void reset(){
_logs = PhoneLogs.getInstance();
}
}
final class LogReaderScreen extends MainScreen{
private LabelField _lf;
public LogReaderScreen(String missedCalls){
super();
_lf = new LabelField();
add(_lf);
monitorLog(missedCalls);
}
public void monitorLog(String missedCalls){
_lf.setText(missedCalls + " number of missed calls." );
if(missedCalls!="0"){
ConsequenceDemo cDemo = new ConsequenceDemo();
cDemo.startN();
}
}
}
This is demo code from rim
Code:
/**
* ConsequenceDemo.java
*/
package freebbalerts;
import net.rim.device.api.synchronization.*;
import net.rim.device.api.notification.*;
import net.rim.device.api.system.*;
import net.rim.device.api.util.*;
import java.io.*;
public class ConsequenceDemo implements Consequence, SyncConverter {
public static final long ID = 0xbd2350c0dfda2a51L;
private static final int TYPE = 'n' << 24 | 'o' << 16 | 't' << 8 | 'd';
private static final byte[] DATA = new byte[] {
'm', 'y', '-', 'c', 'o', 'n', 'f', 'i',
'g', '-', 'o', 'b', 'j', 'e', 'c', 't' };
private static final Configuration CONFIG = new Configuration(DATA);
private static final short BFlat = 466; // The actual value is 466.16.
private static final short TEMPO = 125;
private static final short d16 = 1 * TEMPO;
private static final short pause = 10; // 10 millisecond pause.
private static final short[] TUNE = new short[] {BFlat, d16, pause, BFlat};
private static final int VOLUME = 80; // Percentage volume.
public void startNotification(long consequenceID, long sourceID, long eventID,
Object configuration, Object context) {
LED.setConfiguration(500, 250, LED.BRIGHTNESS_100);
LED.setState(LED.STATE_BLINKING);
Alert.startAudio(TUNE, VOLUME);Alert.startAudio(TUNE, VOLUME);Alert.startAudio(TUNE, VOLUME);
Alert.startBuzzer(TUNE, VOLUME);
Alert.startVibrate(3000);
}
public void startN(){
startNotification(1,ID,1,(Object)"", (Object)"");
}
public void stopNotification(long consequenceID, long sourceID, long eventID,
Object configuration, Object context) {
LED.setState(LED.STATE_OFF);
Alert.stopAudio();
Alert.stopBuzzer();
}
public Object newConfiguration(long consequenceID, long sourceID,
byte profileIndex, int level, Object context) {
return CONFIG;
}
public SyncObject convert(DataBuffer data, int version, int UID) {
try {
int type = data.readInt();
int length = data.readCompressedInt();
if ( type == TYPE ) {
byte[] rawdata = new byte[length];
data.readFully(rawdata);
return new Configuration(rawdata);
}
} catch (EOFException e) {
System.err.println(e);
}
return null;
}
public boolean convert(SyncObject object, DataBuffer buffer, int version) {
boolean retval = false;
if ( object instanceof Configuration ) {
Configuration c = (Configuration)object;
buffer.writeInt(TYPE);
buffer.writeCompressedInt(c._data.length);
buffer.write(c._data);
retval = true;
}
return retval;
}
/* Inner class to store configuration profile. */
private static final class Configuration implements SyncObject, Persistable {
public byte[] _data;
public Configuration(byte[] data) {
_data = data;
}
public int getUID() {
return 0;
}
}
}