나는 com.android.internal API를 사용하여 하나의 안드로이드 응용 프로그램을 만들고 있습니다. 그것들은 Call.java, CallManger.java입니다. 이 클래스들을 위해 Call.java를위한 서브 클래스를 만들었습니다. 이 두 클래스는 여기 http://hi-android.info/src/com/android/internal/telephony/Call.java.html과 http://hi-android.info/src/com/android/internal/telephony/CallManager.java.html입니다. Call.java의ClassCastException 오류
서브 클래스는 다음과 같습니다
공용 클래스 MyCall은 전화를 확장 {
이 같은 CallManger의 예라고1. CallManager cm = CallManager.getInstance();
2. Phone.State state;
3.
4. Phone mDefaultPhone;
5. private final ArrayList<Connection> emptyConnections = new ArrayList<Connection>();
6. List<Call> ringingCall;
7.
8. @Override
9. public List<Connection> getConnections() {
10.
11.
12. state = cm.getState();
13. ringingCall = cm.getForegroundCalls();
14. System.out.println("**inside getConnections="+state);
15. System.out.println("**inside getConnections="+ringingCall);
16. if (ringingCall == null) {
17.
18. System.out.println("**call is null***");
19. return emptyConnections;
20. }
21. else
22. {
23. System.out.println("**call is not null***");
24. return ((Call) ringingCall).getConnections();
}
}
@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() {
List l;
long time = Long.MAX_VALUE;
Connection c;
Connection earliest = null;
l = getConnections();
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;
}
}
이 Bcoz
CallManager cm = CallManager.getInstance();
이 최종 수정 클래스입니다 . 다른 클래스는 CallUpdate.java입니다.
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);
}
}
myConn 값이 null입니다. 이를 위해 myConn의 null이 아닌 값을 얻기 위해 MyCall 클래스의 getConnection 메소드에 코드를 추가했습니다. 24 라인 l = getConnections();
에 :
state = cm.getState();
ringingCall = cm.getForegroundCalls();
System.out.println("**inside getConnections="+state);
System.out.println("**inside getConnections="+ringingCall);
if (ringingCall == null) {
System.out.println("**call is null***");
return emptyConnections;
}
else
{
System.out.println("**call is not null***");
return ((Call) ringingCall).getConnections();
}
하지만 호선에 ClassCastException이 오류를 던지고을 즉. 또한 myConn의 값을 가져 오기 위해 적어도 하나의 발신 통화가 필요합니다. 이 오류를 해결하는 방법?
Thx.
ok Jon thk u. 만나서 반갑습니다 :) – shiv1229
전화로 적극적인 전화를 받으려면 어떻게해야합니까. 나에게 어떤 제안을 해줄 수 있습니까? – shiv1229
@ shiv1229 : 그럼'getForegroundCalls()'을 호출하여 비어 있는지 확인하십시오 ... –