Hello. Can anyone come across a solution to this problem: I track the info about the incoming call, the lifted handset and the end of the call and send it to the server. When processing a single call there are no problems. But when calling the second line there is a problem:

It can be schematically represented as

Действие Состояние телефона ------------------------------------- Звонит <номер1> | RINGING (EXTRA_INCOMING_NUMBER == <номер1>) Подняли <номер1> | OFFHOOK (EXTRA_INCOMING_NUMBER == null) Звонит <номер2> | RINGING (EXTRA_INCOMING_NUMBER == <номер2>) Подняли <номерX> | OFFHOOK (EXTRA_INCOMING_NUMBER == null) <--- Час Ч Положили трубку | IDLE (EXTRA_INCOMING_NUMBER == null) 

How to know what happened in "Hour H":

  1. Reset number1 and went to number2
  2. We reset number 2 and returned to number 1
  3. Postponed number1, switched to number2, returned to number1, and as many more manipulations

Whatever happens, EXTRA_STATE is always OFFHOOK , EXTRA_INCOMING_NUMBER is always null , and indeed BroadcastReceiver , set on android.intent.action.PHONE_STATE , stops working. PhoneStateListener does not suit me, because when calling the second SIM card, its state is always 0, and in my opinion it does not give a solution.

If you need a code, tell me lay out.

How to be? Has anyone encountered a similar problem?

    2 answers 2

    So far, it has not been possible to solve the problem entirely, but the required result has been partially obtained.

    My task is to timely send information about incoming calls to the server. Initially, when the second line appeared, the problem was that at the end of the call, the server received an info only about the last call, and the first one hung active. This problem was solved by storing numbers in a local database and viewing this database as IDLE. The problem with hanging active calls was resolved, but another one appeared - regardless of the actions that took place in the “Hour Hr”, both IDLE calls received one ending date and none of them could be missed. Google’s several-hour picking has brought CallLogs.Call to the class and now, when the phone goes into IDLE mode, numbers are taken from the local database (ActiveCallsDB in the code) and CallLogs.Call gets the duration of the last conversation with this number. My specific problem has been solved, although it’s not elegant, I will be glad if someone comes in handy. But the question remains open.

     if (state.equals("RINGING")) { ringing = true; number = incomingNumber; intentForService.putExtra("number", number); cont.startService(intentForService); SQLiteDatabase db = (new ActiveCallsDB(cont)).getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("phone", number); cv.put("status", "0"); db.insert(ActiveCallsDB.TABLE_NAME, null, cv); db.close(); } else if (ringing && state.equals("OFFHOOK")) { intentForService.putExtra("number", number); intentForService.putExtra("state", 2); cont.startService(intentForService); SQLiteDatabase db = (new ActiveCallsDB(cont)).getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("phone", number); cv.put("status", "2"); db.update(ActiveCallsDB.TABLE_NAME, cv, "phone = ?", new String[] { number }); db.close(); } else if (ringing && state.equals("IDLE")) { try { synchronized (this) { // Ждём, пока ин-фа о звонках запишется в базу Android-а this.wait(1000); } SQLiteDatabase db = (new ActiveCallsDB(cont)).getReadableDatabase(); Cursor cur = db.rawQuery("SELECT * FROM " + ActiveCallsDB.TABLE_NAME, null); if (cur.moveToFirst()) { do { String phoneNumber = cur.getString(cur.getColumnIndex("phone")); String[] projection = new String[] { Calls.NUMBER, Calls.DURATION }; Cursor curForCall = cont.getContentResolver().query(Calls.CONTENT_URI, projection, "number = ?", new String[] { phoneNumber }, Calls.DATE + " desc"); curForCall.moveToFirst(); String duration = curForCall.getString(1); curForCall.close(); intentForService.putExtra("number", phoneNumber); intentForService.putExtra("state", 1); intentForService.putExtra("duration", duration); cont.startService(intentForService); db.delete(ActiveCallsDB.TABLE_NAME, "id = " + cur.getInt(cur.getColumnIndex("id")), null); } while (cur.moveToNext()); } ringing = false; } catch (Throwable e) { e.printStackTrace(); } } 

      I do not understand why you are trying to catch numbers online. If you just need to identify incoming calls and send them to the server, then it is easier to hang up the browser and read the changes in the call list after they are finished.

      ContentObserver mContentObserver = new CallLogContentObserver (new Handler (), context, ""); context.getContentResolver (). registerContentObserver (android.provider.CallLog.Calls.CONTENT_URI, true, mContentObserver);