Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get a Call state of a phone
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8740035/trouble-with-reading-phone-state">Trouble with reading phone state</a> </p> </blockquote> <p>I want to get a call state of phone in my application. I am doing one application in which , When user dial to a number, then my application should come to know whether other side phone is Busy, Not-reachable or power-off states etc. For this I used com.android.internal API's they are Call.java<code>&lt;http://hi-android.info/src/com/android/internal/telephony/Call.java.html&gt;</code>, CallManger.java<code>&lt;http://hi-android.info/src/com/android/internal/telephony/CallManager.java.html&gt;</code> and Connection.java<code>&lt;http://hi-android.info/src/com/android/internal/telephony/Connection.java.html&gt;</code>. I created subclass of Call.java like this:</p> <pre><code>public class MyCall extends Call{ CallManager cm = CallManager.getInstance(); Connection c; Phone mDefaultPhone; private final ArrayList&lt;Connection&gt; emptyConnections = new ArrayList&lt;Connection&gt;(); int size; List&lt;Call&gt; ringingCall = cm.getForegroundCalls(); @Override public List&lt;Connection&gt; getConnections() { System.out.println("**value of list***"+ringingCall.size()); if(ringingCall != null &amp;&amp; !ringingCall.isEmpty()){ System.out.println("inside if****"); System.out.println("**call is not null***"); System.out.println("value of call"+ringingCall); return ((MyCall) ringingCall).getConnections(); } else{ System.out.println("**list is null***"); return emptyConnections; } } @Override public Phone getPhone() { // TODO Auto-generated method stub System.out.println("**inside getPhone***"); return null; } @Override public void hangup() throws CallStateException { // TODO Auto-generated method stub System.out.println("**inside hangUp***"); } @Override public boolean isMultiparty() { // TODO Auto-generated method stub System.out.println("**inside isMultiparty***"); return false; } public Connection getEarliestConnection() { Connection myConn = new MyConnection(); System.out.println("inside EarliestConnection"); List&lt;Connection&gt; 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 &lt; s ; i++) { c = (Connection) l.get(i); long t; t = c.getCreateTime(); if (t &lt; time) { earliest = c; time = t; } } return earliest; } } </code></pre> <p>Here I am getting the ringingCall.size is 0 for that it is executing else part. And one more class is CallUpdate.java.</p> <pre><code>public class CallUpdate { Call myCall = new MyCall(); CallManager cm = CallManager.getInstance(); public Object getCallFailedString(){ Connection 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; } } </code></pre> <p>In this code getting myConn value is null. I called CallManger class is like this:</p> <pre><code>CallManager cm = CallManager.getInstance(); </code></pre> <p>But when I print this getting null pointer exception. <code>System.out.println("value of cm"+cm);</code> why this exception? Can anybody tell me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload