获取呼叫值为空

时间:2012-01-09 14:35:29

标签: java android

在我的代码中,我得到Call的值为null。即我使用的是三个内部API,它们是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

Connection.java

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

我为Call和连接类创建了子类。

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

我这样打电话给CallManger:

CallManager cm = CallManager.getInstance();

我的另一个课程是CallUpdate。它应该给我一个OutgoingCall状态(即其他终端电话的状态是Busy,power-off或not -achable)。

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

}

但是我在上面的Call.java方法中得到Call值为null。

致电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;
    }   
    }

rigingCall值为null。为什么这个值为空?我正在以正确的方式做事吗?请帮助我

提前谢谢。

1 个答案:

答案 0 :(得分:3)

您永远不会在ringingCall课程中初始化MyCall,因此它是null

这会导致myConn null查看您的代码。