mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Use TelephonyManager getCallState() instead of the provided extras
According to the documentation the current call state might be not correctly contained in the extra, and using getCallState() is the right thing to do Might help for #799 (and #756)
This commit is contained in:
+3
-9
@@ -18,6 +18,7 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -35,19 +36,12 @@ public class PhoneCallReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
|
||||
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
|
||||
mSavedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
|
||||
} else {
|
||||
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
|
||||
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
|
||||
int state = 0;
|
||||
if (TelephonyManager.EXTRA_STATE_IDLE.equals(stateStr)) {
|
||||
state = TelephonyManager.CALL_STATE_IDLE;
|
||||
} else if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(stateStr)) {
|
||||
state = TelephonyManager.CALL_STATE_OFFHOOK;
|
||||
} else if (TelephonyManager.EXTRA_STATE_RINGING.equals(stateStr)) {
|
||||
state = TelephonyManager.CALL_STATE_RINGING;
|
||||
}
|
||||
int state = tm.getCallState();
|
||||
onCallStateChanged(context, state, number);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user