How to detect a call Drop in android

2019-02-25 06:17发布

问题:

I'm writing an app that runs on background during a telephone conversation and logs the coordinates to a file after the conversation has end,I know Android telephony API can detect a call manual disconnect by user*(correct me,if I'm wrong)*,

But what I want is to know whether the service disconnection have caused due to call drop,is there a way or an API I can use to achieve this,

All what I need is to programmatically differentiate a disconnected call and a dropped call.

Please help.

回答1:

Try this code, but I am not sure..

private getCallFailedString(Call call) { 

    Phone phone = PhoneApp.getInstance().phone; 
    Connection c = call.getEarliestConnection(); 

    Connection.DisconnectCause cause = c.getDisconnectCause(); 

    switch (cause) { 
        case BUSY: 
        break; 

    case CONGESTION: 
         break; 

    case LOST_SIGNAL: 
         break; 

    case LIMIT_EXCEEDED: 
         break; 

    case POWER_OFF: 
         break; 

    case SIM_ERROR: 
         break; 

    case OUT_OF_SERVICE: 
         break; 

    default: 
         break; 

    } 

}