BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-07-2008, 04:06 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default What are the Project settings required to create a PhoneListner

Please Login to Remove!

I have written a PhoneListener class.

It compiles error free but when I tried running it on the BlackBerry , it did not detect any phone calls

Can some one please say what are the Project settings that I should use ?

I have created it as a background program without any icon
Offline  
Old 07-08-2008, 03:16 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

care to show us the code?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 07-08-2008, 04:11 AM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon

I have send you the link to the file by PM

It is supposed to detect a call but it is not working at all though I have hardly made any large modifications from the sample provided by RIM

Also as my simulator is not working , I could only compile it error free and wasn't able to simulate the Program
Offline  
Old 07-08-2008, 04:14 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
/*
 * SmplCallDiverter.java
 *
 *  <your company here>, 2003-2005
 * Confidential and proprietary.
 */
/*
* SmplCallDiverter
*/
package com.blackberrydeveloper.SmplCallDiverter;


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

import net.rim.blackberry.api.invoke.*;
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.*;
import net.rim.device.api.util.*;
import java.util.*;
import java.lang.*;
import java.io.*;


public final class SmplCallDiverter extends AbstractPhoneListener {
static public void main(String[] args)
{
SmplCallDiverter.registerOnStartup();
}
static private void registerOnStartup()
{
SmplCallDiverter phn_hndl = new SmplCallDiverter();
Phone.addPhoneListener(phn_hndl);
}



private void Dial()
 {

 PhoneArguments args = new PhoneArguments(PhoneArguments.ARG_CALL,"123456789"); 

 Invoke.invokeApplication(Invoke.APP_TYPE_PHONE, args);

}


private boolean SendDigit(String TheNum)
{
PhoneCall PhCll = Phone.getActiveCall();

boolean isOkay;// = True;

isOkay=true;

if ( PhCll != null )
{
isOkay= PhCll.sendDTMFTones(TheNum);

//sleep(200);


}

return isOkay;
}



private SmplCallDiverter(){}
private void checkCall(String ehandler, int callid)
{
PhoneCall callInfo = Phone.getCall(callid);
if ( callInfo != null ) {
/*
* Event Handler: ehandler
* Telephone No.: callInfo.getDisplayPhoneNumber();
* Elapsed Time : callInfo.getElapsedTime();
* Call Status : callInfo.getStatusString();
*/
}
}
// A call has been added to a conference call
public void callAdded(int callId) { checkCall("callAdded", callId); }
// User answered a call
public void callAnswered(int callId)
{ checkCall("callAnswered", callId); }
// Conference call established
public void callConferenceCallEstablished(int callId)
{ checkCall("callConferenceCallEstablished", callId); }
// Network indicates a connected event
public void callConnected(int callId)
{ checkCall("callConnected", callId); }
// Direct-connect call connected
public void callDirectConnectConnected(int callId)
{ checkCall("callDirectConnectConnected", callId); }
// Direct-connect call disconnected
public void callDirectConnectDisconnected(int callId)
{ checkCall("callDirectConnectDisconnected", callId); }
// Call disconnected
public void callDisconnected(int callId)
{ checkCall("callDisconnected", callId); }
// User ended call
public void callEndedByUser(int callId)
{ checkCall("callEndedByUser", callId); }
// Call has been placed on "hold"
public void callHeld(int callId)
{ checkCall("callHeld", callId); }
// New call has arrived
public void callIncoming(int callId)

{ 

Dialog.alert(" An Incomming Call ");

checkCall("callIncoming", callId); 

}

// Outbound call initiated by the handheld
public void callInitiated(int callid)
{ 


PhoneCall callInfo2 = Phone.getCall(callid);

Dialog.alert(callInfo2.getDisplayPhoneNumber());

Dialog.alert(" The number being dialled is " +  callInfo2.getDisplayPhoneNumber());


StringBuffer strBuffer=new StringBuffer(callInfo2.getDisplayPhoneNumber());

// Wrong and Unneeded for(int a=0 ; a < strBuffer.length() ; a++){

int a;

a=1;

//string pls;

//pls="+";



//if ((strBuffer.charAt(a) == "+"))

if((Character.isDigit(strBuffer.charAt(a))))
{
System.out.println( " Starts with a number ");
}
else
 {

System.out.println( " It is an international Call ");

Dial();

SendDigit(callInfo2.getDisplayPhoneNumber()); //.charAt(b));

}      
          
          
         //{  System.out.println( " It is an international Call ")
         
         
// END the call

/*

EventInjector.KeyCodeEvent pressEndKey=new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_DOWN,( char)Keypad.KEY_END,KeypadListener.STATUS_NOT_FROM_KEYPAD,100);

EventInjector.KeyCodeEvent releaseEndKey=new EventInjector.KeyCodeEvent(KeyCodeEvent.KEY_UP,(char)Keypad.KEY_END,KeypadListener.STATUS_NOT_FROM_KEYPAD,100);

EventInjector.invokeEvent(pressEndKey);

EventInjector.invokeEvent(releaseEndKey);


*/



//Dial();

                //}




//for(int b=1 ; b < strBuffer.length() ; b++){
    
 //SendDigit(callInfo2.getDisplayPhoneNumber()); //.charAt(b));


checkCall("callInitiated", callid);

 }
 
 
 
 
 
// Call removed from a conference call
public void callRemoved(int callId)
{ checkCall("callRemoved", callId); }
// Call taken off of "hold"
public void callResumed(int callId)
{ checkCall("callResumed", callId); }
// Call is waiting
public void callWaiting(int callid)
{ checkCall("callWaiting", callid); }
// Conference call has been terminated
// (all members disconnected)
public void conferenceCallDisconnected(int callId)
{ checkCall("conferenceCallDisconnected", callId); }
// Call failed
public void callFailed(int callId, int reason)
{

checkCall("callFailed", callId);
// determine reason
}
}
Offline  
Old 07-08-2008, 04:15 AM   #5 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Simon

I have uploaded the whole code
Offline  
Old 07-08-2008, 04:18 AM   #6 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you have to extend either application or uiapplication (or midlet) to create a blackberry program.

move your phonelistener to another class and add it from your application.
Code:
Phone.addPhoneListener(new AbstractPhoneListenerImpl(theApp));
to keep it simple you hand your application object to the listener to enable it to run code directly. if you have your code working you should switch this to a callback interface.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 07-08-2008, 04:31 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon

I am totally confused

Can you please show how I should implement it ?

Do I have to extend the UIApplication even though it is a background program ?
Offline  
Old 07-08-2008, 04:55 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Simon

Do you mean something like this ?




Code:
public final class SmplCallDiverter extends uiApplication{
static public void main(String[] args)
{
SmplCallDiverter.registerOnStartup();
}
static private void registerOnStartup()
{
NwPhoneDialer phn_hndl = new NwPhoneDialer ();
Phone.addPhoneListener(phn_hndl);
}


Public class NwPhoneDialer extends AbstractPhoneListener { 
// code

}
Offline  
Old 07-08-2008, 06:13 AM   #9 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes.
if you put each class into an own file you have a better overview.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 07-08-2008, 10:24 AM   #10 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon

I am not able to implement it corectly

Can you please show me the correct declaration ?
Offline  
Old 07-08-2008, 10:46 AM   #11 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

this is the main method of my UiApplication.

Code:
public static void main(final String[] args) {
            Phone.addPhoneListener(new IncomingInterceptPhoneListener());
        }
Code:
public class IncomingInterceptPhoneListener extends AbstractPhoneListener {

    public final void callConnected(final int callId) {...
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 07-08-2008, 12:34 PM   #12 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Simon

Do you mean all the functions and call handling procedures hould be in one file , IncomingInterceptPhoneListener

And after writing all the associated functions and all I should create a new file and instantiate the previous file ie IncomingInterceptPhoneListener ?

Is that what I should do ?
Offline  
Old 07-08-2008, 12:43 PM   #13 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Vodafone
Posts: 134
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also I get a warning , multiple entry ( main ) is defined multiply
Offline  




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