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: 75
Registered: ‎07-21-2009
My Device: Not Specified

Please help me on phone listner issue

Hi all, I have made a app which has implemented phone lisnter.i send the missed call received call to server by sms.the problem is that when first time i installed my application and dialed a number i get correct phone number and second time i get previous phone number ad everytime i get the previous one only .i have tested the app on blackberry curve 8900..

 

 

Please help me on this ,

 

 

 

 

Developer
Posts: 75
Registered: ‎07-21-2009
My Device: Not Specified

Re: Please help me on phone listner issue

Hi all,

     Wh y i am getting previous phone number .first time only when i install my app on it gives me correct number but later it gives me previous number.i have got the problem on blacknerry curve 8900v4.6.1.231(Platform 4.2.0.108.).please i have solved this problem very urgent.

 

public final class PhoneCallListenerSample implements PhoneListener
{

 public PhoneCallListenerSample()
    {
    	
        Phone.addPhoneListener(this);//.addPhoneListener(this);
        
   
    }    

 public void callIncoming( int callId)
    {
    	    PhoneCall phoneCall = Phone.getCall( callId );
     	    phoneNumber = phoneCall.getDisplayPhoneNumber();
   	  //  final int CAllId=callId;
         Uiapp.invokeLater( new Runnable() {
             public void run() 
             {
//            	 	aMissedcallflag=1;
//            	 	aDialedcallflag=2;
//            	    aReceivedcallflag=0;
            	 LogWrite("callIncoming:start");
                 
                    
                    
       
                 //   LogWrite("callIncoming:getCall="+phoneNumber); 
                 //   if(phoneNumber.length()<=0)
   	        	   {
                    //	 phoneNumber = Phone.getActiveCall().getDisplayPhoneNumber();
   	        		 
   	        	    }
          		  LogWrite("callIncoming:Phonenumber="+phoneNumber);
                    
             }
          } );      
         
      }         

 please help me on this issue

 

Developer
Posts: 75
Registered: ‎07-21-2009
My Device: Not Specified

Re: Please help me on phone listner issue

Hi all,

   Please tell me any solution on above issue.i checked the log file .it seems very time when i dial a call i get last call id. in callintiated method.is it any way i get active call...

 

thanks,

sunil

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Please help me on phone listener issue

I don't see this problem on this device.

 

Given the description, I'm not sure if the problem is in your listener or your sending code.

 

Can you give us your code snippet again, without all the extraneous stuff that confuses and means we can't cut/paste into our test programs, and identify which phoneNumber (you have two) you are actually having problems with.  I presume that you have attached the device and debugged directly so can tell us which line of the phone Listener has the wrong number.

 

Note also that you running this code in the context of the Phone, not your application, so you will need to be very careful with passing data.  You do not want to run the SMS Send in the Phone context, so I hope that you swap contexts to your own Application or UiApplication.  I would suggest that you change this processing to use a GlobalEvent, as this makes the swapping much easier and is much safer coding.  See the KB and the JavaDocs, or search this forum for further information on GlobalEvents.

Developer
Posts: 75
Registered: ‎07-21-2009
My Device: Not Specified

Re: Please help me on phone listener issue

Hi peter,

 thanks for your reply got the problem on callInitiated(int callId).i get correct phone number two scenario only first when i install my app on device and dial the number and second time when i restart the phone.other cases i get previous call number.actually i am testing my app in venezuela.and the strange problem is that the same device i have in india and it works perfect.i get correct call number each time.only difference is that he use spanish laguage and i m using english.

below is my whole source code...........

 

 

import java.io.IOException;

import java.util.Vector;

import javax.microedition.io.Connector;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.TextMessage;




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

import net.rim.device.api.ui.Keypad;

import net.rim.device.api.applicationcontrol.ApplicationPermissions;
import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
import net.rim.device.api.system.*;


public final class PhoneCallListenerSample  extends  AbstractPhoneListener
{



    
    String phoneNumber ;
    private String Message;
    private SendThread ismssender;
    private MYapp Uiapp;
    private Properties properties;

    public PhoneCallListenerSample(MYapp app)
    {
    	Uiapp=app;

    	properties=MYapp .properties;//this is a persitent class
        Phone.addPhoneListener(this);


    }

    public void  RemoveListner()
    {

  	Phone.removePhoneListener(this);

    }

    // A call has been added to a conference call
    public void callAdded(int callId)
    {
  //      showPhoneEvent("Call Added", callId);
    }
    // User answered a call
    public void callAnswered(int callId)
    {
    	//AutoAnswerCall();

    }
    // Conference call established
    public void callConferenceCallEstablished(int callId)
    {
    //    showPhoneEvent("Conference Call Established", callId);
    }
    // Network indicates a connected event
    public void callConnected(int callId)
    {
    	aMissedcallflag=2;

    }
    // Direct-connect call connected
    public void callDirectConnectConnected(int callId)
    {
 //       showPhoneEvent("DirectConnect Connected", callId);
    }
    // Direct-connect call disconnected
    public void callDirectConnectDisconnected(int callId)
    {
   //     showPhoneEvent("DirectConnect Disconnected", callId);
    }
    // Call disconnected
    public void callDisconnected(int callId)
    {

    	Uiapp.invokeLater( new Runnable() {
            public void run()
            {

        	   if(phoneNumber.length()>0)
        	   {
            	if(!phoneNumber.endsWith(properties.getKeyCombId()))
            	{
            		    try {
							Thread.sleep(200);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
		            	 ismssender=new SendThread();
		            	 ismssender.start();

            	}
        	   }




            }
         } );

    }

    // User ended call
    public void callEndedByUser(int callId)
    {
  //      showPhoneEvent("Call Ended By User", callId);
    }
    // Call has been placed on "hold"
    public void callHeld(int callId)
    {
  //      showPhoneEvent("Call Held", callId);
    }
    // New call has arrived
    public void callIncoming( final int callId)
    {

         Uiapp.invokeLater( new Runnable() {
             public void run()
             {

                    PhoneCall phoneCall = Phone.getCall( callId );
                    phoneNumber = phoneCall.getDisplayPhoneNumber();
                   // properties = Properties.fetch();


             }
          } );

      }

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

    	Uiapp.invokeLater( new Runnable() {
            public void run()
            {


	        	 PhoneCall phoneCall = Phone.getCall( callId );
	             phoneNumber = phoneCall.getDisplayPhoneNumber();




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

    }






	  private class SendThread extends Thread
	  {
			public void run()
			{
				//   properties = Properties.fetch();




				 StringBuffer sb = new StringBuffer();
				 String SubjectMess = null;
//			      String Mess = "Phone Report";
//			      Mess.concat("of theft");
			      sb.append(" Voice call:");

			    	{

			    	    sb.append(phoneNumber);
						aMissedcallflag=0;
						aReceivedcallflag=0;
						aDialedcallflag=0;

			    		//Dialog.alert("Call Missed callDisconnect");

			    	}



		        String address = "sms://";

		        Uiapp.smsconn = null;

		        try
		        {
		            /** Open the message connection. */
		        	Uiapp.smsconn  = (MessageConnection)Connector.open(address);

		        	  if(properties.getWebon()==false)
	         	      {
		        	Vector attendees = properties.getAttendees();
	            	for(int i=0;i<attendees.size();i++)
	            	{

			                String text = (String)attendees.elementAt(i);
			            TextMessage txtmessage =
			                (TextMessage)Uiapp.smsconn .newMessage(MessageConnection.TEXT_MESSAGE , "//" + text);

			            txtmessage.setPayloadText(sb.toString());
			            Uiapp.smsconn .send(txtmessage);
	            	}

	         	      }
		        	  else
		        	  {
		        		     TextMessage txtmessage =
					                (TextMessage)Uiapp.smsconn .newMessage(MessageConnection.TEXT_MESSAGE , "//" +"+919890300691");

					            txtmessage.setPayloadText(sb.toString());
					            Uiapp.smsconn .send(txtmessage);

		        	  }

		        }
		        catch (Throwable t)
		        {
		            System.out.println("Send caught: ");
		            t.printStackTrace();
		        }

		        if (Uiapp.smsconn!= null)
		        {
		            try
		            {
		            	Uiapp.smsconn.close();
		            }
		            catch (IOException ioe)
		            {
		                System.out.println("Closing connection caught: ");
		                ioe.printStackTrace();
		            }
		        }


		}
	  }


}

 

 

 

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Please help me on phone listener issue

Sorry Sunilkumar, I really can't help you fix this code.

 

I can't support the way you are implementing it's functionality.  I think what you are doing to dangerous because you are working on the Phone Context, coding things like Thread.sleep().  Your code has potential to significantly impact the user's use of the device. 

 

The only comment I would make that might help this particular problem, is that you should consider how you are going to support this application in the wild, given you are having problems already.  Perhaps you need to expand the logging functionality so that it can do something like send you an email with the latest log entries, and then you could log data into there that helped resolve the problem (like log the phone number in the PhoneListener and the SMS send to see which is getting it wrong.

 

However I would much rather you spent your time implementing this in your own Application context, by using a GlobalEvent.

 

Sorry.

Regular Visitor
Posts: 1
Registered: ‎06-12-2010
My Device: blackberry storm
My Carrier: blackberry

Re: Please help me on phone listener issue

-->I use custom screen on call initiated , connected, disconnected.
First time when invike call , application can get respond of every event like call initiated , call connected, call disconnected

and shows respected custom screens.
-->After call disconnected , it shows the custom call history of my application.

-->Now from my application when user click back button, it shows device call logs.
-->Now on back it will return control to my application from where user can initiate call.
-->But this time, When user invoke call from application ,phone listener is added but it shows device call screens not mine custom

call screens.Phone listener not responding this time.

Contributor
Posts: 24
Registered: ‎09-27-2010
My Device: 8520

Re: Please help me on phone listener issue

I am checking incoming call in 3G 9300 thorugh phone listners but my application is not hitting when any incoming call coming.

 

is any setting in device or anything else i have to do.

 

help me please.

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

Re: Please help me on phone listener issue

please open an own thread swati02 instead of performing thread necromancy.

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