shiv1229
shiv1229

Reputation: 357

Getting Call value is null

In my code I am getting a value of Call is null. i.e I am using three internal API's they are Call.java

http://hi-android.info/src/com/android/internal/telephony/Call.java.html

CallManger.java

http://hi-android.info/src/com/android/internal/telephony/CallManager.java.html and

Connection.java

http://hi-android.info/src/com/android/internal/telephony/Connection.java.html.

I created subclass for Call and connection class.

public class MyCall extends Call{   

    CallManager cm = CallManager.getInstance(); 
    Phone.State state;
    Connection c;
     Phone mDefaultPhone;
     private final ArrayList<Connection> emptyConnections = new ArrayList<Connection>();    


     Call ringingCall;

    @Override
    public List<Connection> getConnections() {              
        System.out.println("before if****"+ringingCall);
    if(ringingCall != null){                
        System.out.println("inside if****");
        ringingCall = (Call) cm.getForegroundCalls();
        System.out.println("**call is not null***");
        System.out.println("value of call"+ringingCall);
        return ((Call) ringingCall).getConnections();
    }           
            else
             {
                 System.out.println("**list is  null***");
                 return emptyConnections;
        }   
    }

    @Override
    public Phone getPhone() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void hangup() throws CallStateException {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean isMultiparty() {
        // TODO Auto-generated method stub
        return false;
    }

    public Connection
    getEarliestConnection() {
        System.out.println("inside EarliestConnection"); 
        List l;
        long time = Long.MAX_VALUE;
        Connection c;
        Connection earliest = null;

        l = getConnections();
        System.out.println("value of connection is=="+l); 
        if (l == null) {
            return null;
        }else if ( l.size() == 0)
        {
            return null;
        }


        for (int i = 0, s = l.size() ; i < s ; i++) {
            c = (Connection) l.get(i);
            long t;

            t = c.getCreateTime();

            if (t < time) {
                earliest = c;
                time = t;
            }
        }

        return earliest;
    }
  }

I called CallManger like this :

CallManager cm = CallManager.getInstance();

My another class is CallUpdate . It should give me a OutgoingCall States(i.e states of other end phone is Busy, power-off or not-reachable) .

public class CallUpdate {   

    Call myCall = new MyCall();
    Connection myConn = new MyConnection();
    CallManager cm = CallManager.getInstance();

        public Object getCallFailedString(){

           myConn = myCall.getEarliestConnection();
           System.out.println("myConn is  ******"+myConn);
           System.out.println("myCall is  ******"+myCall);  

           if(myConn == null){
                System.out.println("myConn is null ******");
                return null;
           }                
          else
            {
               Connection.DisconnectCause cause = myConn.getDisconnectCause();                       
               System.out.println("myconn is not null ******"+cause);   


                switch(cause){

                 case BUSY :
                   System.out.println("inside busy");
                 break;

                 case NUMBER_UNREACHABLE :
                    System.out.println("inside un-reachable");
                 break;

                case POWER_OFF :
                   System.out.println("inside power off");
                 break;  
              }     


        }
    return myConn;
 }

}

But I am getting Call value is null in the above method of Call.java.

Call ringingCall

    public List<Connection> getConnections() {              
     System.out.println("before if****"+ringingCall);
    if(ringingCall != null){                
    System.out.println("inside if****");
    ringingCall = (Call) cm.getForegroundCalls();
    System.out.println("**call is not null***");
    System.out.println("value of call"+ringingCall);
    return ((Call) ringingCall).getConnections();
}           
        else
         {
             System.out.println("**list is  null***");
             return emptyConnections;
    }   
    }

The rigingCall values is null. Why this value is null? Is I am doing in correct way ?. plz help me

Thx in advance.

Upvotes: 1

Views: 226

Answers (1)

Brian Roach
Brian Roach

Reputation: 76918

You never initialize ringingCall in your MyCall class, therefore it is null.

This leads to myConn also being null looking through your code.

Upvotes: 3

Related Questions