Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 45
Registered: ‎01-16-2009
My Device: Not Specified
Accepted Solution

Manipulation of Phonlog but no success in deleting an item

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

}

}

 

 

 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Manipulation of Phonlog but no success in deleting an item

phonelogs get updated when you start the BB. dunno why rim implemented it like this.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Manipulation of Phonlog but no success in deleting an item

I had similar dificulties once.

 

I resolved this by deleting the 'wrong' entry and creating a new one.



"Listen carefully, I shall say this only once"
Developer
Posts: 45
Registered: ‎01-16-2009
My Device: Not Specified

Re: Manipulation of Phonlog but no success in deleting an item

I tried this with no success. Could you provide a code snipset for deleting the last log entry an creating  a new one?
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Manipulation of Phonlog but no success in deleting an item

[ Edited ]

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(PhoneLogs.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.FOLDER_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 Smiley Wink

 

Message Edited by myraddin on 01-26-2009 03:15 PM


"Listen carefully, I shall say this only once"
Developer
Posts: 45
Registered: ‎01-16-2009
My Device: Not Specified

Re: Manipulation of Phonlog but no success in deleting an item

I tried it but still strange behavior.

 

 

logs.addCall(myLog);

logs.deleteCall(logs.numberOfCalls(PhoneLogs.FOLDER_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?

 

 

 

 

Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Manipulation of Phonlog but no success in deleting an item

The invokeLater turned out to be crucial for my scenario.

 

 

You can learn more here:

http://tinyurl.com/dlg36t

 

Or search through the forums.



"Listen carefully, I shall say this only once"
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Manipulation of Phonlog but no success in deleting an item

Any luck ?


"Listen carefully, I shall say this only once"
Developer
Posts: 45
Registered: ‎01-16-2009
My Device: Not Specified

Re: Manipulation of Phonlog but no success in deleting an item

I didn't have any time to try but a colleaque has managed to do the manipulation using the "invoke later" method.
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: Manipulation of Phonlog but no success in deleting an item

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 Smiley Sad

 

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 Smiley Sad

 



"Listen carefully, I shall say this only once"