01-26-2009 08:11 AM
Hi,
i have written a small application that should manipulate the last entry in the phonelog. I want to overrite the dialed number with a custom one . Only the custom number should be in the log. Writing the custom number to the log works fine but deleting the dialed number doesn't work. I have read in an other thread that der was a problem with deleting phonlog items in v4.2. I am developing on version 4.5 does the problem still exists or have i done somethin wrong (see the listing below).
import java.util.Vector;
import net.rim.blackberry.api.phone.phonelogs.CallLog;
import net.rim.blackberry.api.phone.phonelogs.PhoneCallLog;
import net.rim.blackberry.api.phone.phonelogs.PhoneCallLogID;
import net.rim.blackberry.api.phone.phonelogs.PhoneLogs;
import net.rim.device.api.system.PersistentStore;
import net.rim.device.api.util.StringMatch;
public class PhoneLogListener implements
net.rim.blackberry.api.phone.phonelogs.PhoneLogListener {
private AsteriskMenuItem caller;
private boolean editFlag = false;
public PhoneLogListener (AsteriskMenuItem theMenuItem)
{
caller = theMenuItem;
}
public void callLogAdded(CallLog cl) {
PhoneCallLog myLog = ((PhoneCallLog)cl);
//get ne number to be write in the log
String participantNumber = (myLog.getParticipant()).getNumber();
//get the current service number from the persistent store (String)
Vector persStore = (Vector) (PersistentStore.getPersistentObject( 0xd4b6b5eeea339daL )).getContents();
String currentServiceNumber = (String)persStore.firstElement();
//if the participantnumber starts with the servicenumber we did come from the application and want to edit the logentry
if (participantNumber.startsWith(currentServiceNumber));
{
//set the number we want to show
myLog.setParticipant(new PhoneCallLogID(caller.getPhoneNumber2()));
//remove the listener to prevent an endless loop
PhoneLogs.removeListener(this);
//---> the folowing does not work
//(PhoneLogs.getInstance()).deleteCall(0, PhoneLogs.FOLDER_NORMAL_CALLS);
//---> the folowing works
(PhoneLogs.getInstance()).addCall(myLog);
}
}
public void callLogRemoved(CallLog cl) {
// TODO Auto-generated method stub
}
public void callLogUpdated(CallLog cl, CallLog oldCl) {
// TODO Auto-generated method stub
}
public void reset() {
// TODO Auto-generated method stub
}
}
Solved! Go to Solution.
01-26-2009 08:34 AM
01-26-2009 08:41 AM
I had similar dificulties once.
I resolved this by deleting the 'wrong' entry and creating a new one.
01-26-2009 08:43 AM
01-26-2009 08:55 AM - edited 01-26-2009 09:15 AM
Sure:
Application.getApplication().invokeLater(new Runnable()
{
public void run()
{PhoneLogs logs = PhoneLogs.getInstance();
if (logs.numberOfCalls(PhoneLogs.FOLDER_NORMAL_CALLS) >= 2)
{// FOR AN EXAMPLE I WILL COPY THE LAST LOG DETAILS AND CREATE NEW ONE
PhoneCallLog lastLog = (PhoneCallLog)logs.callAt(logs.numberOfCalls(Phone
Logs.FOLDER_NORMAL_CALLS) - 1, PhoneLogs.FOLDER_NORMAL_CALLS);
PhoneCallLog newLog = new PhoneCallLog(lastLog.getDate(), lastLog.getType(), lastLog.getDuration(), lastLog.getStatus(), lastLog.getParticipant(), lastLog.getNotes());
logs.addCall(newLog);// NOW GO AND DELETE THE OLD ONE
Application.getApplication().invokeLater(new Runnable()
{
public void run()
{
PhoneLogs logs = PhoneLogs.getInstance();
if (logs.numberOfCalls(PhoneLogs.FOLDER_NORMAL_CALLS) >= 2)
{// homework: figure out which to delete -1 or -2 :)
logs.deleteCall(logs.numberOfCalls(PhoneLogs.FOLDE
R_NORMAL_CALLS) (- 2 || -1), PhoneLogs.FOLDER_NORMAL_CALLS);
}
}
});
}
}
}, 500,false);
Sorry if you need to fix it a little bit since I had to truncate a lot of surrounding code.
But to my experience, invokeLater is the key to success ![]()
01-26-2009 09:22 AM
I tried it but still strange behavior.
logs.addCall(myLog);
logs.deleteCall(logs.numberOfCalls(PhoneLogs.FOLDE
R_NORMAL_CALLS) -2, PhoneLogs.FOLDER_NORMAL_CALLS);
logs.deleteCall(logs.numberOfCalls(PhoneLogs.FOLDER_NORMAL_CALLS) -1, PhoneLogs.FOLDER_NORMAL_CALLS);
- with those both lines it only delets the previous added new entry
- only the line with index -2, does delete the the previous added new entry
- only the line with index -1, does nothing, both numbers are in the log, new create one and the one that was dialed.
Why does index -1 not delete the number. Why do you delete the new entry (-2). I do not unterstand the invokeLater thing. Can't i handle the things i want to do inside the PhonlogListener.callLogAdded method?
01-26-2009 09:46 AM
The invokeLater turned out to be crucial for my scenario.
You can learn more here:
Or search through the forums.
03-05-2009 07:56 AM
03-05-2009 08:14 AM
03-05-2009 08:36 AM
Great.
But I (later on) discovered
that in fact the call is not correctly removed. It is still present somewhere. For instance:
delete an exisiting xxx call log.
create a xxx call log. (but don't delete it)
In call log history you will see that the xxx log has more than one entry, although you deleted it ![]()
Even more, if you use call log->options->general options->Phone list view and put : most recent (for instance, you will see that the log was not deleted at all.
So there is another place where the callLog information is stored ![]()