BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-28-2008, 05:04 PM   #1
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default PhoneListener how it works

Please Login to Remove!

Hi Fellows, I am new in mobile programming, I have been reading about classes on BB guide, I start doing my first App and I choose Phone classes, taking pieces of code from guide and try to run it on MDS simulator but I do not make it work.

here is piece of code I am using please advice what I am doing wrong.

package Blocker;
import net.rim.blackberry.api.phone.*;

public final class CallBlock extends AbstractPhoneListener
{
private Callblock(){}

public static void main(String argv[])
{
CallBlock.Startup();
}

static private void Startup()
{
CallBlock Tel= new CallBlock();
Phone.addPhoneListener(Tel);
}


public void checkCall(String ehandler, int callid)
{
PhoneCall pc = Phone.getCallId(callID);
String phoneNumber = pc.getDisplayPhoneNumber();
System.out.println(phoneNumber);
if (phoneNumber.equals("22670029"))
{
System.out.println("Blocked!!!!!");
}
}
}
Offline  
Old 05-29-2008, 02:32 AM   #2
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

to run an application you have to extend Application or UiApplication, depending on your needs to interfere with the UI.
you don't have to put everything into one class, just put up another class for your application.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-29-2008, 10:00 AM   #3
holy3daps
Thumbs Must Hurt
 
Join Date: Apr 2006
Location: Boston
Model: 8900
Carrier: AT&T
Posts: 98
Default

Hi!

So you might want to sprinkle more System.out.println() statements through your code, to find out what's going wrong and where. This is sometimes known as "debugging by printf". Also make sure that the JDE's debugger is attached and active - System.out.println() only prints to a debugger window, not to the device's screen or event log. Look up the API for EventLogger if you want to make use of the device's event log facility to see log statements on a real device (real devices ignore System.out.println() but you can attach a JDE's debugger to a real device via a USB cable and the debugger will show those statements).

Be careful: Phone.addPhoneListener() will add another listener every time you execute your code - generally, you only want to do this once. Each listener will be executed - if you launch your application twice, two listeners get added and both will get executed when the Phone class runs through its list of listeners for each Phone event.

Cheers,

karl
__________________
Karl G. Kowalski
---------------
Owns a RAZR
Develops for BlackBerry
So next phone will be........an iPhone 3G!
Offline  
Old 05-29-2008, 10:40 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

as long as one tests on the simulator it is therefor useful to mark the application or entry point as autostart
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-30-2008, 11:14 AM   #5
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

Quote:
Originally Posted by simon.hain View Post
as long as one tests on the simulator it is therefor useful to mark the application or entry point as autostart
Thanks for your comment, as I said I just starting with this, is interesting what you said, but how I Configure it to start/autostart and be confident that will be run just once

Can you guys guide me how do this


thanks

Nelson
Offline  
Old 06-02-2008, 02:46 AM   #6
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

if you use the JDE (at least partially): create a new project, set it to 'alternatce cldc entry point' and select your main application below. check 'autostart' and 'run as system module'. enter some string, like 'autostartup', as an argument for the main method.

in your main application check the parameter of main:
(a simple example)
Code:
public static void main(String[] args) {
         if (args.length > 0 && args[0].equals("autostartup")) {
                  Notificator.registerNotifications();
                   OptionsManager.registerOptionsProvider(new OptionsProviderImpl());
        } else {
                 X theApp = new X();
                 theApp.enterEventDispatcher();
         }
}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-08-2008, 07:09 PM   #7
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

I have doing some tries how use phone listener but noone has been succesfully, does anyone have a sample code, it will very helpfull, I am just a student, please give me a hand.

thanks
Offline  
Old 06-09-2008, 02:20 AM   #8
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

Here is some sample application. I wrote it in the form editor -> there are no imports. Maybe there is some misspelling but it should compile. Put every code snippet into its according java file.

for simplicitys sake i will not use a proper callback routine but hand over the application itself.

Code:
//simple phonelistener application

public class MyPhoneListenerApplication extends UiApplication{

private MainScreen myPhoneListenerScreen;

public static void main(String[] args) {
MyPhoneListenerApplication theApp = new MyPhoneListenerApplication();
Phone.addPhoneListener(new MyPhoneListener(theApp));
theApp.enterEventDispatcher();
}

public MyPhoneListenerApplication(){
myPhoneListenerScreen = new MyPhoneListenerScreen();
pushScreen(myPhoneListenerScreen);

}

public void writeOnScreen(String text){
myPhoneListenerScreen.writeOnScreen(text);
}
}
Code:
public class MyPhoneListener extends AbstractPhoneListener {

private MyPhoneListenerApplication theApp;

public MyPhoneListener(MyPhoneListenerApplication theApp){
this.theApp=theApp;
}

public void callConnected(int callId) {
PhoneCall call = Phone.getCall(callId);
theApp.invokeLater(new Runnable(){
public void run(){
theApp.writeOnScreen("call from "+call.getDisplayPhoneNumber());
}});

}

}
Code:
public MyPhoneListenerScreen extends MainScreen{

private LabelField labelField;

public MyPhoneListenerScreen(){
setTitle("myPhoneListener");
labelField = new LabelField();
add(labelField);
}

public void writeOnScreen(String text){
labelField.setText(text);
}


}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 06-09-2008, 09:46 PM   #9
nchreyes
New Member
 
Join Date: May 2008
Model: 8300
PIN: N/A
Carrier: Claro
Posts: 12
Default

Thanks for your Code, even it doesnt compile, it shows me some how use those classes and my code is working, now my problem is that this code should rund instead default phonelistener, but it doesn't.
the main idea it when a call arrives phone is compare to a list, if number is on the list, phone should not ring. any idea

thanks for all your patience and support.

Nelson
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


USA Windows VPS RDP Server/ Windows VPS Hosting - 4GB RAM + 150GB HDD picture

USA Windows VPS RDP Server/ Windows VPS Hosting - 4GB RAM + 150GB HDD

$11.99



Hoffman Exhaust Fan Enclosure Laser Server Cabinet A-DB275 picture

Hoffman Exhaust Fan Enclosure Laser Server Cabinet A-DB275

$199.99



NEW MOXA NPORT 5150 serial server DHL Fast delivery picture

NEW MOXA NPORT 5150 serial server DHL Fast delivery

$182.28



Used & Tested MOXA NPORT5232 2 Port RS422/485 Ethernet Device Server picture

Used & Tested MOXA NPORT5232 2 Port RS422/485 Ethernet Device Server

$195.08



MultiTech Systems Fax Finder FF440 Fax Server No PSU - mounting bracket damaged picture

MultiTech Systems Fax Finder FF440 Fax Server No PSU - mounting bracket damaged

$400.00



Wti Console Server + PDU CPM-800-1-EA picture

Wti Console Server + PDU CPM-800-1-EA

$550.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.