如果考虑程序的独立性,只能监听log了
可参考我的代码:
private static final String CAUSE_STRING_FLAG = "onDisconnect: cause =";
private static final String LOCAL_STRING_FLAG = "onDisconnect: cause = LOCAL";
private Thread mLogcatThread = new Thread(new Runnable() {
public void run() {
Process mLogcatProc = null;
BufferedReader reader = null;
try {
//to get logcat info
mLogcatProc = Runtime.getRuntime().exec(new String[] { "logcat","CallNotifier:D*:S" });
reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (mStopMonitor || line.indexOf(ACTIVED_STRING_FLAG) > 0) {
//
break;
}